Search in sources :

Example 1 with KmsClient

use of com.google.crypto.tink.KmsClient in project tink by google.

the class KmsAeadKeyManagerTest method setUp.

@Before
public void setUp() throws Exception {
    KmsClient kmsClient = new GcpKmsClient().withCredentials(TestUtil.SERVICE_ACCOUNT_FILE);
    KmsClients.add(kmsClient);
    Config.register(AeadConfig.TINK_1_0_0);
}
Also used : GcpKmsClient(com.google.crypto.tink.integration.gcpkms.GcpKmsClient) KmsClient(com.google.crypto.tink.KmsClient) GcpKmsClient(com.google.crypto.tink.integration.gcpkms.GcpKmsClient) Before(org.junit.Before)

Example 2 with KmsClient

use of com.google.crypto.tink.KmsClient in project tink by google.

the class KmsEnvelopeAeadKeyManager method getPrimitive.

/**
 * @param key {@code KmsEnvelopeAeadKey} proto
 */
@Override
public Aead getPrimitive(MessageLite key) throws GeneralSecurityException {
    if (!(key instanceof KmsEnvelopeAeadKey)) {
        throw new GeneralSecurityException("expected KmsEnvelopeAeadKey proto");
    }
    KmsEnvelopeAeadKey keyProto = (KmsEnvelopeAeadKey) key;
    validate(keyProto);
    String keyUri = keyProto.getParams().getKekUri();
    KmsClient kmsClient = KmsClients.get(keyUri);
    Aead remote = kmsClient.getAead(keyUri);
    return new KmsEnvelopeAead(keyProto.getParams().getDekTemplate(), remote);
}
Also used : KmsEnvelopeAeadKey(com.google.crypto.tink.proto.KmsEnvelopeAeadKey) GeneralSecurityException(java.security.GeneralSecurityException) Aead(com.google.crypto.tink.Aead) ByteString(com.google.protobuf.ByteString) KmsClient(com.google.crypto.tink.KmsClient)

Example 3 with KmsClient

use of com.google.crypto.tink.KmsClient in project tink by google.

the class KmsAeadKeyManager method getPrimitive.

/**
 * @param key  {@code KmsAeadKey} proto
 */
@Override
public Aead getPrimitive(MessageLite key) throws GeneralSecurityException {
    if (!(key instanceof KmsAeadKey)) {
        throw new GeneralSecurityException("expected KmsAeadKey proto");
    }
    KmsAeadKey keyProto = (KmsAeadKey) key;
    validate(keyProto);
    String keyUri = keyProto.getParams().getKeyUri();
    KmsClient kmsClient = KmsClients.get(keyUri);
    return kmsClient.getAead(keyUri);
}
Also used : KmsAeadKey(com.google.crypto.tink.proto.KmsAeadKey) GeneralSecurityException(java.security.GeneralSecurityException) ByteString(com.google.protobuf.ByteString) KmsClient(com.google.crypto.tink.KmsClient)

Aggregations

KmsClient (com.google.crypto.tink.KmsClient)3 ByteString (com.google.protobuf.ByteString)2 GeneralSecurityException (java.security.GeneralSecurityException)2 Aead (com.google.crypto.tink.Aead)1 GcpKmsClient (com.google.crypto.tink.integration.gcpkms.GcpKmsClient)1 KmsAeadKey (com.google.crypto.tink.proto.KmsAeadKey)1 KmsEnvelopeAeadKey (com.google.crypto.tink.proto.KmsEnvelopeAeadKey)1 Before (org.junit.Before)1