use of javax.crypto.Cipher 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.Cipher in project cas by apereo.
the class DefaultRegisteredServiceCipherExecutor method initializeCipherBasedOnServicePublicKey.
/**
* Initialize cipher based on service public key.
*
* @param publicKey the public key
* @param registeredService the registered service
* @return the false if no public key is found
* or if cipher cannot be initialized, etc.
*/
private Cipher initializeCipherBasedOnServicePublicKey(final PublicKey publicKey, final RegisteredService registeredService) {
try {
LOGGER.debug("Using public key [{}] to initialize the cipher", registeredService.getPublicKey());
final Cipher cipher = Cipher.getInstance(publicKey.getAlgorithm());
cipher.init(Cipher.ENCRYPT_MODE, publicKey);
LOGGER.debug("Initialized cipher in encrypt-mode via the public key algorithm [{}]", publicKey.getAlgorithm());
return cipher;
} catch (final Exception e) {
LOGGER.warn("Cipher could not be initialized for service [{}]. Error [{}]", registeredService, e.getMessage());
}
return null;
}
use of javax.crypto.Cipher 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.Cipher in project OpenAttestation by OpenAttestation.
the class HisPrivacyCAWebService2ImplTest method encryptRSA.
public static byte[] encryptRSA(byte[] text, PublicKey pubRSA) throws Exception {
Cipher cipher = Cipher.getInstance("RSA", "BC");
cipher.init(Cipher.ENCRYPT_MODE, pubRSA);
return cipher.doFinal(text);
}
use of javax.crypto.Cipher 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;
}
Aggregations