use of javax.crypto.spec.IvParameterSpec in project zeppelin by apache.
the class Authentication method decrypt.
private String decrypt(String value, String initVector) {
LOG.debug("IV is {}, IV length is {}", initVector, initVector.length());
if (StringUtils.isBlank(value) || StringUtils.isBlank(initVector)) {
LOG.error("String to decode or salt is not provided");
return StringUtils.EMPTY;
}
try {
IvParameterSpec iv = generateIV(initVector);
Key key = generateKey();
Cipher cipher = Cipher.getInstance(CIPHER_MODE);
cipher.init(Cipher.DECRYPT_MODE, key, iv);
byte[] decryptedString = Base64.decodeBase64(toBytes(value));
decryptedString = cipher.doFinal(decryptedString);
return new String(decryptedString);
} catch (GeneralSecurityException e) {
LOG.error("Error when decrypting", e);
return StringUtils.EMPTY;
}
}
use of javax.crypto.spec.IvParameterSpec in project UltimateAndroid by cymcsg.
the class TripleDES method decrypt.
/**
* Decrypt the message with TripleDES
*
* @param message
* @return
* @throws Exception
*/
public static String decrypt(String message) throws Exception {
if (message == null || message == "")
return "";
byte[] values = Base64decoding(message, 0);
final MessageDigest md = MessageDigest.getInstance("SHA-1");
final byte[] digestOfPassword = md.digest(token.getBytes("utf-8"));
final byte[] keyBytes = copyOf(digestOfPassword, 24);
for (int j = 0, k = 16; j < 8; ) {
keyBytes[k++] = keyBytes[j++];
}
final SecretKey key = new SecretKeySpec(keyBytes, "DESede");
String s1 = "12345678";
byte[] bytes = s1.getBytes();
final IvParameterSpec iv = new IvParameterSpec(bytes);
final Cipher decipher = Cipher.getInstance("DESede/CBC/PKCS5Padding");
decipher.init(Cipher.DECRYPT_MODE, key, iv);
final byte[] plainText = decipher.doFinal(values);
return new String(plainText, "UTF-8");
}
use of javax.crypto.spec.IvParameterSpec in project Openfire by igniterealtime.
the class K method A.
byte[] A(byte[] abyte0, int i, int j) {
if (C == null)
return abyte0;
try {
byte[] abyte1 = new byte[16];
IvParameterSpec ivparameterspec = new IvParameterSpec(abyte1);
Cipher cipher = Cipher.getInstance("AES/CBC/NoPadding");
if (E == Encryption.ENCRYPT)
cipher.init(1, C, ivparameterspec);
if (E == Encryption.DECRYPT)
cipher.init(2, C, ivparameterspec);
return cipher.doFinal(abyte0, i, j);
} catch (NoSuchAlgorithmException nosuchalgorithmexception) {
D.error(nosuchalgorithmexception.getMessage(), nosuchalgorithmexception);
} catch (NoSuchPaddingException nosuchpaddingexception) {
D.error(nosuchpaddingexception.getMessage(), nosuchpaddingexception);
} catch (InvalidKeyException invalidkeyexception) {
D.error(invalidkeyexception.getMessage(), invalidkeyexception);
} catch (BadPaddingException badpaddingexception) {
D.error(badpaddingexception.getMessage(), badpaddingexception);
} catch (IllegalBlockSizeException illegalblocksizeexception) {
D.error(illegalblocksizeexception.getMessage(), illegalblocksizeexception);
} catch (InvalidAlgorithmParameterException invalidalgorithmparameterexception) {
D.error(invalidalgorithmparameterexception.getMessage(), invalidalgorithmparameterexception);
}
return null;
}
use of javax.crypto.spec.IvParameterSpec in project Signal-Android by WhisperSystems.
the class DecryptingPartInputStream method initializeCipher.
private Cipher initializeCipher(SecretKeySpec key) throws InvalidKeyException, InvalidAlgorithmParameterException, NoSuchAlgorithmException, NoSuchPaddingException, IOException {
Cipher cipher = Cipher.getInstance("AES/CBC/PKCS5Padding");
IvParameterSpec iv = readIv(cipher.getBlockSize());
cipher.init(Cipher.DECRYPT_MODE, key, iv);
return cipher;
}
use of javax.crypto.spec.IvParameterSpec in project remusic by aa112901.
the class AESTools method encrpty.
public static String encrpty(String paramString) {
MessageDigest messageDigest = null;
try {
messageDigest = MessageDigest.getInstance("MD5");
} catch (NoSuchAlgorithmException e) {
e.printStackTrace();
}
messageDigest.update(INPUT.getBytes());
byte[] stringBytes = messageDigest.digest();
StringBuilder stringBuilder = new StringBuilder(stringBytes.length * 2);
for (int i = 0; i < stringBytes.length; i++) {
stringBuilder.append(CHARS[((stringBytes[i] & 0xF0) >>> 4)]);
stringBuilder.append(CHARS[(stringBytes[i] & 0xF)]);
}
String str = stringBuilder.toString();
SecretKeySpec localSecretKeySpec = new SecretKeySpec(str.substring(str.length() / 2).getBytes(), "AES");
Cipher localCipher;
try {
localCipher = Cipher.getInstance("AES/CBC/PKCS5Padding");
localCipher.init(1, localSecretKeySpec, new IvParameterSpec(IV.getBytes()));
return URLEncoder.encode(new String(BytesHandler.getChars(localCipher.doFinal(paramString.getBytes()))), "utf-8");
} catch (NoSuchAlgorithmException e) {
e.printStackTrace();
} catch (NoSuchPaddingException e) {
e.printStackTrace();
} catch (InvalidKeyException e) {
e.printStackTrace();
} catch (InvalidAlgorithmParameterException e) {
e.printStackTrace();
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
} catch (IllegalBlockSizeException e) {
e.printStackTrace();
} catch (BadPaddingException e) {
e.printStackTrace();
}
return "";
}
Aggregations