List of usage examples for javax.crypto Cipher DECRYPT_MODE
int DECRYPT_MODE
To view the source code for javax.crypto Cipher DECRYPT_MODE.
Click Source Link
From source file:corner.services.impl.DESedeEncryptServiceImpl.java
public byte[] decrypt(byte[] src, byte[] keybyte) { try {/*from w w w . j a v a 2s .co m*/ SecretKey deskey = new SecretKeySpec(keybyte, Algorithm); Cipher c1 = Cipher.getInstance(Algorithm); c1.init(Cipher.DECRYPT_MODE, deskey); return c1.doFinal(src); } catch (java.security.NoSuchAlgorithmException e1) { e1.printStackTrace(); } catch (javax.crypto.NoSuchPaddingException e2) { e2.printStackTrace(); } catch (java.lang.Exception e3) { e3.printStackTrace(); } return null; }
From source file:net.mindengine.oculus.frontend.web.Auth.java
public static User decodeUser(String encodedString) { try {/*w ww . jav a 2 s. com*/ ObjectInputStream ois = new ObjectInputStream( new ByteArrayInputStream(Base64.decodeBase64(encodedString.getBytes()))); SealedObject sealedObject = (SealedObject) ois.readObject(); ois.close(); Cipher dcipher = Cipher.getInstance("DES"); dcipher.init(Cipher.DECRYPT_MODE, secrectAuthKey); User user = (User) sealedObject.getObject(dcipher); return user; } catch (Exception e) { return null; } }
From source file:CipherSocket.java
public InputStream getInputStream() throws IOException { InputStream is = delegate == null ? super.getInputStream() : delegate.getInputStream(); Cipher cipher = null;//from w ww. j a va 2 s.c o m try { cipher = Cipher.getInstance(algorithm); int size = cipher.getBlockSize(); byte[] tmp = new byte[size]; Arrays.fill(tmp, (byte) 15); IvParameterSpec iv = new IvParameterSpec(tmp); cipher.init(Cipher.DECRYPT_MODE, key, iv); } catch (Exception e) { e.printStackTrace(); throw new IOException("Failed to init cipher: " + e.getMessage()); } CipherInputStream cis = new CipherInputStream(is, cipher); return cis; }
From source file:com.dasol.util.AES256Util.java
public String aesDecode(String str) throws java.io.UnsupportedEncodingException, NoSuchAlgorithmException, NoSuchPaddingException, InvalidKeyException, InvalidAlgorithmParameterException, IllegalBlockSizeException, BadPaddingException { Cipher c = Cipher.getInstance("AES/CBC/PKCS5Padding"); c.init(Cipher.DECRYPT_MODE, keySpec, new IvParameterSpec(iv.getBytes("UTF-8"))); byte[] byteStr = Base64.decodeBase64(str.getBytes()); return new String(c.doFinal(byteStr), "UTF-8"); }
From source file:com.zotoh.core.crypto.JavaOfuscator.java
private String decrypt(String encoded) throws Exception { if (isEmpty(encoded)) { return encoded; }//from w ww. ja v a 2s. c o m Cipher c = getCipher(Cipher.DECRYPT_MODE); ByteOStream baos = new ByteOStream(); byte[] p = Base64.decodeBase64(encoded); byte[] out = new byte[Math.max(4096, c.getOutputSize(p.length))]; int n = c.update(p, 0, p.length, out, 0); if (n > 0) { baos.write(out, 0, n); } n = c.doFinal(out, 0); if (n > 0) { baos.write(out, 0, n); } return asString(baos.asBytes()); }
From source file:cn.org.once.cstack.utils.CustomPasswordEncoder.java
public String decode(CharSequence pass) { Cipher cipher;// www . j a va2s .co m String decryptString = null; try { byte[] encryptText = Base64.decodeBase64(pass.toString()); cipher = Cipher.getInstance(ALGO); cipher.init(Cipher.DECRYPT_MODE, generateKey()); decryptString = new String(cipher.doFinal(encryptText)); } catch (Exception e) { e.printStackTrace(); } return decryptString; }
From source file:com.glaf.core.security.SecurityUtils.java
/** * DES/* w ww.j a v a2 s .c om*/ * * @param data * * @param key * ???8? * @return ? */ public static String decode(String key, String data) { if (data == null) { return null; } try { DESKeySpec dks = new DESKeySpec(key.getBytes()); SecretKeyFactory keyFactory = SecretKeyFactory.getInstance("DES"); // key??8? Key secretKey = keyFactory.generateSecret(dks); Cipher cipher = Cipher.getInstance(ALGORITHM_DES); IvParameterSpec iv = new IvParameterSpec("12345678".getBytes()); AlgorithmParameterSpec paramSpec = iv; cipher.init(Cipher.DECRYPT_MODE, secretKey, paramSpec); return new String(cipher.doFinal(hex2byte(data.getBytes()))); } catch (Exception ex) { ex.printStackTrace(); throw new SecurityException(ex); } }
From source file:gov.nih.nci.security.util.AESEncryption.java
public AESEncryption(String passphrase, boolean isMD5Hash) throws EncryptionException { try {//from w w w.j a v a2 s . c o m this.provider = new BouncyCastleProvider(); SecretKeySpec skey = getSKeySpec(passphrase, isMD5Hash); encryptCipher = Cipher.getInstance(AES_ENCRYPTION_SCHEME, provider); decryptCipher = Cipher.getInstance(AES_ENCRYPTION_SCHEME, provider); encryptCipher.init(Cipher.ENCRYPT_MODE, skey); AlgorithmParameters ap = encryptCipher.getParameters(); decryptCipher.init(Cipher.DECRYPT_MODE, skey, ap); } catch (NoSuchAlgorithmException e) { throw new EncryptionException(e); } catch (NoSuchPaddingException e) { throw new EncryptionException(e); } catch (InvalidKeyException e) { throw new EncryptionException(e); } catch (InvalidAlgorithmParameterException e) { throw new EncryptionException(e); } }
From source file:edu.harvard.i2b2.analysis.security.RijndaelAlgorithm.java
public RijndaelAlgorithm(String password, int ksize, String encryptionType, String emethod) throws Exception { SecretKeySpec skeySpec = new SecretKeySpec(password.getBytes("UTF-8"), encryptionType); cipherEnc = Cipher.getInstance(emethod); cipherDec = Cipher.getInstance(emethod); keySize = ksize;/*from w w w. jav a2s . c o m*/ //setKey( pword ); cipherEnc.init(Cipher.ENCRYPT_MODE, skeySpec); cipherDec.init(Cipher.DECRYPT_MODE, skeySpec); }
From source file:com.sshtools.j2ssh.transport.cipher.BlowfishCbc.java
/** * * * @param mode/* w ww. j a v a 2 s .c o m*/ * @param iv * @param keydata * * @throws AlgorithmOperationException */ public void init(int mode, byte[] iv, byte[] keydata) throws AlgorithmOperationException { try { cipher = Cipher.getInstance("Blowfish/CBC/NoPadding"); // Create a 16 byte key byte[] actualKey = new byte[16]; System.arraycopy(keydata, 0, actualKey, 0, actualKey.length); SecretKeySpec keyspec = new SecretKeySpec(actualKey, "Blowfish"); // Create the cipher according to its algorithm cipher.init(((mode == ENCRYPT_MODE) ? Cipher.ENCRYPT_MODE : Cipher.DECRYPT_MODE), keyspec, new IvParameterSpec(iv, 0, cipher.getBlockSize())); } catch (NoSuchPaddingException nspe) { log.error("Blowfish initialization failed", nspe); throw new AlgorithmOperationException("No Padding not supported"); } catch (NoSuchAlgorithmException nsae) { log.error("Blowfish initialization failed", nsae); throw new AlgorithmOperationException("Algorithm not supported"); } catch (InvalidKeyException ike) { log.error("Blowfish initialization failed", ike); throw new AlgorithmOperationException("Invalid encryption key"); /*} catch (InvalidKeySpecException ispe) { throw new AlgorithmOperationException("Invalid encryption key specification");*/ } catch (InvalidAlgorithmParameterException ape) { log.error("Blowfish initialization failed", ape); throw new AlgorithmOperationException("Invalid algorithm parameter"); } }