/** * @param serializedKey serialized {@code AesCtrHmacAeadKey} proto */ @Override public Aead getPrimitive(ByteString serializedKey) throws GeneralSecurityException { try { AesCtrHmacAeadKey keyProto = AesCtrHmacAeadKey.parseFrom(serializedKey); return getPrimitive(keyProto); } catch (InvalidProtocolBufferException e) { throw new GeneralSecurityException("expected serialized AesCtrHmacAeadKey proto", e); } }
/** * @param serializedKeyFormat serialized {@code AesCtrHmacAeadKeyFormat} proto * @return new {@code AesCtrHmacAeadKey} proto */ @Override public MessageLite newKey(ByteString serializedKeyFormat) throws GeneralSecurityException { try { AesCtrHmacAeadKeyFormat format = AesCtrHmacAeadKeyFormat.parseFrom(serializedKeyFormat); return newKey(format); } catch (InvalidProtocolBufferException e) { throw new GeneralSecurityException("expected serialized AesCtrHmacAeadKeyFormat proto", e); } }
private KeyManager<Aead> aeadKeyManager(String typeUrl) throws GeneralSecurityException { switch (typeUrl) { case AesCtrHmacAeadKeyManager.TYPE_URL: return new AesCtrHmacAeadKeyManager(); case AesEaxKeyManager.TYPE_URL: return new AesEaxKeyManager(); case AesGcmKeyManager.TYPE_URL: return new AesGcmKeyManager(); case ChaCha20Poly1305KeyManager.TYPE_URL: return new ChaCha20Poly1305KeyManager(); case KmsAeadKeyManager.TYPE_URL: return new KmsAeadKeyManager(); case KmsEnvelopeAeadKeyManager.TYPE_URL: return new KmsEnvelopeAeadKeyManager(); default: throw new GeneralSecurityException( String.format("No support for primitive 'Aead' with key type '%s'.", typeUrl)); } } }
/** * @param key {@code AesCtrHmacAeadKey} proto */ @Override public Aead getPrimitive(MessageLite key) throws GeneralSecurityException { if (!(key instanceof AesCtrHmacAeadKey)) { throw new GeneralSecurityException("expected AesCtrHmacAeadKey proto"); } AesCtrHmacAeadKey keyProto = (AesCtrHmacAeadKey) key; validate(keyProto); return new EncryptThenAuthenticate( (IndCpaCipher) Registry.getPrimitive( AesCtrKeyManager.TYPE_URL, keyProto.getAesCtrKey()), (Mac) Registry.getPrimitive(MacConfig.HMAC_TYPE_URL, keyProto.getHmacKey()), keyProto.getHmacKey().getParams().getTagSize()); }
/** * @param serializedKeyFormat serialized {@code AesCtrHmacAeadKeyFormat} proto * @return {@code KeyData} proto with a new {@code AesCtrHmacAeadKey} proto */ @Override public KeyData newKeyData(ByteString serializedKeyFormat) throws GeneralSecurityException { AesCtrHmacAeadKey key = (AesCtrHmacAeadKey) newKey(serializedKeyFormat); return KeyData.newBuilder() .setTypeUrl(TYPE_URL) .setValue(key.toByteString()) .setKeyMaterialType(KeyData.KeyMaterialType.SYMMETRIC) .build(); }