use of com.google.crypto.tink.subtle.AesCtrJceCipher in project tink by google.
the class AesCtrKeyManagerTest method getPrimitive.
@Test
public void getPrimitive() throws Exception {
AesCtrKey key = factory.createKey(createFormat(14, 32));
IndCpaCipher managerCipher = manager.getPrimitive(key, IndCpaCipher.class);
IndCpaCipher directCipher = new AesCtrJceCipher(key.getKeyValue().toByteArray(), 14);
byte[] plaintext = Random.randBytes(20);
assertThat(directCipher.decrypt(managerCipher.encrypt(plaintext))).isEqualTo(plaintext);
}
use of com.google.crypto.tink.subtle.AesCtrJceCipher in project tink by google.
the class AesCtrKeyManager method getPrimitive.
/**
* @param key {@code AesCtrKey} proto
*/
@Override
public AesCtrJceCipher getPrimitive(MessageLite key) throws GeneralSecurityException {
if (!(key instanceof AesCtrKey)) {
throw new GeneralSecurityException("expected AesCtrKey proto");
}
AesCtrKey keyProto = (AesCtrKey) key;
validate(keyProto);
return new AesCtrJceCipher(keyProto.getKeyValue().toByteArray(), keyProto.getParams().getIvSize());
}
Aggregations