Search in sources :

Example 1 with HmacKeyManager

use of com.google.crypto.tink.mac.HmacKeyManager in project tink by google.

the class AesCtrHmacAeadKeyManager method validateKey.

@Override
public void validateKey(AesCtrHmacAeadKey key) throws GeneralSecurityException {
    Validators.validateVersion(key.getVersion(), getVersion());
    new AesCtrKeyManager().validateKey(key.getAesCtrKey());
    new HmacKeyManager().validateKey(key.getHmacKey());
}
Also used : HmacKeyManager(com.google.crypto.tink.mac.HmacKeyManager)

Example 2 with HmacKeyManager

use of com.google.crypto.tink.mac.HmacKeyManager in project tink by google.

the class AesCtrHmacAeadKeyManager method keyFactory.

@Override
public KeyFactory<AesCtrHmacAeadKeyFormat, AesCtrHmacAeadKey> keyFactory() {
    return new KeyFactory<AesCtrHmacAeadKeyFormat, AesCtrHmacAeadKey>(AesCtrHmacAeadKeyFormat.class) {

        @Override
        public void validateKeyFormat(AesCtrHmacAeadKeyFormat format) throws GeneralSecurityException {
            new AesCtrKeyManager().keyFactory().validateKeyFormat(format.getAesCtrKeyFormat());
            new HmacKeyManager().keyFactory().validateKeyFormat(format.getHmacKeyFormat());
            Validators.validateAesKeySize(format.getAesCtrKeyFormat().getKeySize());
        }

        @Override
        public AesCtrHmacAeadKeyFormat parseKeyFormat(ByteString byteString) throws InvalidProtocolBufferException {
            return AesCtrHmacAeadKeyFormat.parseFrom(byteString, ExtensionRegistryLite.getEmptyRegistry());
        }

        @Override
        public AesCtrHmacAeadKey createKey(AesCtrHmacAeadKeyFormat format) throws GeneralSecurityException {
            AesCtrKey aesCtrKey = new AesCtrKeyManager().keyFactory().createKey(format.getAesCtrKeyFormat());
            HmacKey hmacKey = new HmacKeyManager().keyFactory().createKey(format.getHmacKeyFormat());
            return AesCtrHmacAeadKey.newBuilder().setAesCtrKey(aesCtrKey).setHmacKey(hmacKey).setVersion(getVersion()).build();
        }

        @Override
        public Map<String, KeyFactory.KeyFormat<AesCtrHmacAeadKeyFormat>> keyFormats() throws GeneralSecurityException {
            Map<String, KeyFactory.KeyFormat<AesCtrHmacAeadKeyFormat>> result = new HashMap<>();
            result.put("AES128_CTR_HMAC_SHA256", createKeyFormat(16, 16, 32, 16, HashType.SHA256, KeyTemplate.OutputPrefixType.TINK));
            result.put("AES128_CTR_HMAC_SHA256_RAW", createKeyFormat(16, 16, 32, 16, HashType.SHA256, KeyTemplate.OutputPrefixType.RAW));
            result.put("AES256_CTR_HMAC_SHA256", createKeyFormat(32, 16, 32, 32, HashType.SHA256, KeyTemplate.OutputPrefixType.TINK));
            result.put("AES256_CTR_HMAC_SHA256_RAW", createKeyFormat(32, 16, 32, 32, HashType.SHA256, KeyTemplate.OutputPrefixType.RAW));
            return Collections.unmodifiableMap(result);
        }
    };
}
Also used : AesCtrKey(com.google.crypto.tink.proto.AesCtrKey) HashMap(java.util.HashMap) ByteString(com.google.protobuf.ByteString) HmacKeyManager(com.google.crypto.tink.mac.HmacKeyManager) AesCtrHmacAeadKeyFormat(com.google.crypto.tink.proto.AesCtrHmacAeadKeyFormat) ByteString(com.google.protobuf.ByteString) AesCtrHmacAeadKeyFormat(com.google.crypto.tink.proto.AesCtrHmacAeadKeyFormat) AesCtrKeyFormat(com.google.crypto.tink.proto.AesCtrKeyFormat) HmacKeyFormat(com.google.crypto.tink.proto.HmacKeyFormat) HmacKey(com.google.crypto.tink.proto.HmacKey)

Aggregations

HmacKeyManager (com.google.crypto.tink.mac.HmacKeyManager)2 AesCtrHmacAeadKeyFormat (com.google.crypto.tink.proto.AesCtrHmacAeadKeyFormat)1 AesCtrKey (com.google.crypto.tink.proto.AesCtrKey)1 AesCtrKeyFormat (com.google.crypto.tink.proto.AesCtrKeyFormat)1 HmacKey (com.google.crypto.tink.proto.HmacKey)1 HmacKeyFormat (com.google.crypto.tink.proto.HmacKeyFormat)1 ByteString (com.google.protobuf.ByteString)1 HashMap (java.util.HashMap)1