/** * @return a Aead primitive from a {@code keysetHandle}. * @throws GeneralSecurityException */ public static Aead getPrimitive(KeysetHandle keysetHandle) throws GeneralSecurityException { return getPrimitive(keysetHandle, /* keyManager= */ null); }
@Override public MessageLite newKey(ByteString unused) throws GeneralSecurityException { return newKey(); }
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)); } } }
/** * Init AeadConfig in the Tink library. */ private AeadDemo() { try { AeadConfig.register(); } catch (GeneralSecurityException ex) { log.error("Failed to initialize Tink", ex); } }
/** @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); }
AesCtrHmacAeadKeyManager() throws GeneralSecurityException { Registry.registerKeyManager(new AesCtrKeyManager()); }
/** @param serializedKey serialized {@code AesGcmKey} proto */ @Override public Aead getPrimitive(ByteString serializedKey) throws GeneralSecurityException { try { AesGcmKey keyProto = AesGcmKey.parseFrom(serializedKey); return getPrimitive(keyProto); } catch (InvalidProtocolBufferException e) { throw new GeneralSecurityException("expected AesGcmKey proto"); } }
/** @param serializedKey serialized {@code AesCtrKey} proto */ @Override public AesCtrJceCipher getPrimitive(ByteString serializedKey) throws GeneralSecurityException { try { AesCtrKey keyProto = AesCtrKey.parseFrom(serializedKey); return getPrimitive(keyProto); } catch (InvalidProtocolBufferException e) { throw new GeneralSecurityException("expected serialized AesCtrKey proto", e); } }
/** * @param serializedKey serialized {@code KmsAeadKey} proto */ @Override public Aead getPrimitive(ByteString serializedKey) throws GeneralSecurityException { try { KmsAeadKey keyProto = KmsAeadKey.parseFrom(serializedKey); return getPrimitive(keyProto); } catch (InvalidProtocolBufferException e) { throw new GeneralSecurityException("expected KmsAeadKey proto", e); } }
@Override public Aead getPrimitive(ByteString serialized) throws GeneralSecurityException { try { ChaCha20Poly1305Key keyProto = ChaCha20Poly1305Key.parseFrom(serialized); return getPrimitive(keyProto); } catch (InvalidProtocolBufferException e) { throw new GeneralSecurityException("invalid ChaCha20Poly1305 key", e); } }
/** * @param serializedKeyFormat serialized {@code KmsEnvelopeAeadKeyFormat} proto * @return new {@code KmsEnvelopeAeadKey} proto */ @Override public MessageLite newKey(ByteString serializedKeyFormat) throws GeneralSecurityException { try { KmsEnvelopeAeadKeyFormat format = KmsEnvelopeAeadKeyFormat.parseFrom(serializedKeyFormat); return newKey(format); } catch (InvalidProtocolBufferException e) { throw new GeneralSecurityException("expected serialized KmsEnvelopeAeadKeyFormat proto", e); } }
/** @param serializedKey serialized {@code KmsEnvelopeAeadKey} proto */ @Override public Aead getPrimitive(ByteString serializedKey) throws GeneralSecurityException { try { KmsEnvelopeAeadKey keyProto = KmsEnvelopeAeadKey.parseFrom(serializedKey); return getPrimitive(keyProto); } catch (InvalidProtocolBufferException e) { throw new GeneralSecurityException("expected serialized KmSEnvelopeAeadKey proto", e); } }
/** @param serializedKey serialized {@code AesEaxKey} proto */ @Override public Aead getPrimitive(ByteString serializedKey) throws GeneralSecurityException { try { AesEaxKey keyProto = AesEaxKey.parseFrom(serializedKey); return getPrimitive(keyProto); } catch (InvalidProtocolBufferException e) { throw new GeneralSecurityException("expected serialized AesEaxKey proto", e); } }
/** * @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); } }
private void validate(AesCtrKeyFormat format) throws GeneralSecurityException { Validators.validateAesKeySize(format.getKeySize()); validate(format.getParams()); }
private byte[] decrypt(KeysetHandle keysetHandle, byte[] cipherText) throws GeneralSecurityException { Aead aead = AeadFactory.getPrimitive(keysetHandle); return aead.decrypt(cipherText, ASSOCIATED_DATA.getBytes()); } }
/** * Init AeadConfig in the Tink library. */ private AeadWithSavedKeyDemo() { try { AeadConfig.register(); } catch (GeneralSecurityException ex) { log.error("Failed to initialize Tink", ex); } }
@Override public MessageLite newKey(MessageLite unused) throws GeneralSecurityException { return newKey(); }
/** * Tries to register with the {@link Registry} all instances of {@link * com.google.crypto.tink.Catalogue} and {@link com.google.crypto.tink.KeyManager} needed to * handle Aead key types supported in Tink. * * <p>Because Aead key types depend on {@link com.google.crypto.tink.Mac} key types, this method * also registers all Mac catalogues and key managers. * * @deprecated use {@link #register} */ @Deprecated public static void init() throws GeneralSecurityException { register(); }
/** * Registers with the {@code Registry} all Aead key types released with the latest version of * Tink. * * <p>Deprecated-yet-still-supported key types are registered in so-called "no new key"-mode, * which allows for usage of existing keys forbids generation of new key material. * * @deprecated use {@link #register} */ @Deprecated public static void registerStandardKeyTypes() throws GeneralSecurityException { register(); } }