Search in sources :

Example 1 with AesCtrJceCipher

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);
}
Also used : AesCtrKey(com.google.crypto.tink.proto.AesCtrKey) IndCpaCipher(com.google.crypto.tink.subtle.IndCpaCipher) AesCtrJceCipher(com.google.crypto.tink.subtle.AesCtrJceCipher) Test(org.junit.Test)

Example 2 with AesCtrJceCipher

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());
}
Also used : AesCtrKey(com.google.crypto.tink.proto.AesCtrKey) GeneralSecurityException(java.security.GeneralSecurityException) AesCtrJceCipher(com.google.crypto.tink.subtle.AesCtrJceCipher)

Aggregations

AesCtrKey (com.google.crypto.tink.proto.AesCtrKey)2 AesCtrJceCipher (com.google.crypto.tink.subtle.AesCtrJceCipher)2 IndCpaCipher (com.google.crypto.tink.subtle.IndCpaCipher)1 GeneralSecurityException (java.security.GeneralSecurityException)1 Test (org.junit.Test)1