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;
}
use of javax.crypto.Cipher in project Signal-Android by WhisperSystems.
the class EncryptingPartOutputStream method initializeCipher.
private Cipher initializeCipher(Mac mac, SecretKeySpec key) throws IOException, InvalidKeyException, NoSuchAlgorithmException, NoSuchPaddingException {
Cipher cipher = Cipher.getInstance("AES/CBC/PKCS5Padding");
cipher.init(Cipher.ENCRYPT_MODE, key);
byte[] ivBytes = cipher.getIV();
mac.update(ivBytes);
super.write(ivBytes, 0, ivBytes.length);
return cipher;
}
use of javax.crypto.Cipher in project Signal-Android by WhisperSystems.
the class MasterCipher method encryptBytes.
public byte[] encryptBytes(byte[] body) {
try {
Cipher cipher = getEncryptingCipher(masterSecret.getEncryptionKey());
Mac mac = getMac(masterSecret.getMacKey());
byte[] encryptedBody = getEncryptedBody(cipher, body);
byte[] encryptedAndMacBody = getMacBody(mac, encryptedBody);
return encryptedAndMacBody;
} catch (GeneralSecurityException ge) {
Log.w("bodycipher", ge);
return null;
}
}
use of javax.crypto.Cipher in project Signal-Android by WhisperSystems.
the class MasterSecretUtil method getCipherFromPassphrase.
private static Cipher getCipherFromPassphrase(String passphrase, byte[] salt, int iterations, int opMode) throws GeneralSecurityException {
SecretKey key = getKeyFromPassphrase(passphrase, salt, iterations);
Cipher cipher = Cipher.getInstance(key.getAlgorithm());
cipher.init(opMode, key, new PBEParameterSpec(salt, iterations));
return cipher;
}
Aggregations