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());
}
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);
}
};
}
Aggregations