use of com.google.crypto.tink.proto.AesCtrKey in project tink by google.
the class TestUtil method createAesCtrHmacAeadKeyData.
/**
* @return a {@code KeyData} containing a {@code AesCtrHmacAeadKey}.
*/
public static KeyData createAesCtrHmacAeadKeyData(byte[] aesCtrKeyValue, int ivSize, byte[] hmacKeyValue, int tagSize) throws Exception {
AesCtrKey aesCtrKey = createAesCtrKey(aesCtrKeyValue, ivSize);
HmacKey hmacKey = createHmacKey(hmacKeyValue, tagSize);
AesCtrHmacAeadKey keyProto = AesCtrHmacAeadKey.newBuilder().setAesCtrKey(aesCtrKey).setHmacKey(hmacKey).build();
return createKeyData(keyProto, AeadConfig.AES_CTR_HMAC_AEAD_TYPE_URL, KeyData.KeyMaterialType.SYMMETRIC);
}
use of com.google.crypto.tink.proto.AesCtrKey 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