@Test public void testBasicEncryption() throws Exception { EllipticCurveType curve = EllipticCurveType.NIST_P384; HashType hashType = HashType.SHA256; EcPointFormat primaryPointFormat = EcPointFormat.UNCOMPRESSED; EcPointFormat rawPointFormat = EcPointFormat.COMPRESSED; KeyTemplate primaryDemKeyTemplate = AeadKeyTemplates.AES128_CTR_HMAC_SHA256; KeyTemplate rawDemKeyTemplate = AeadKeyTemplates.AES128_CTR_HMAC_SHA256; byte[] primarySalt = "some salt".getBytes("UTF-8"); byte[] rawSalt = "other salt".getBytes("UTF-8"); EciesAeadHkdfPrivateKey primaryPrivProto = TestUtil.generateEciesAeadHkdfPrivKey( curve, hashType, primaryPointFormat, primaryDemKeyTemplate, primarySalt); Key primaryPriv = TestUtil.createKey( TestUtil.createKeyData( primaryPrivProto, new EciesAeadHkdfPrivateKeyManager().getKeyType(), KeyData.KeyMaterialType.ASYMMETRIC_PRIVATE), 8, KeyStatusType.ENABLED, OutputPrefixType.RAW); Key primaryPub = TestUtil.createKey( TestUtil.createKeyData( primaryPrivProto.getPublicKey(), new EciesAeadHkdfPublicKeyManager().getKeyType(), KeyData.KeyMaterialType.ASYMMETRIC_PUBLIC), 42, KeyStatusType.ENABLED, OutputPrefixType.RAW); EciesAeadHkdfPrivateKey rawPrivProto = TestUtil.generateEciesAeadHkdfPrivKey( curve, hashType, rawPointFormat, rawDemKeyTemplate, rawSalt); Key rawPriv = TestUtil.createKey( TestUtil.createKeyData( rawPrivProto, new EciesAeadHkdfPrivateKeyManager().getKeyType(), KeyData.KeyMaterialType.ASYMMETRIC_PRIVATE), 11, KeyStatusType.ENABLED, OutputPrefixType.RAW); Key rawPub = TestUtil.createKey( TestUtil.createKeyData( rawPrivProto.getPublicKey(), new EciesAeadHkdfPublicKeyManager().getKeyType(), KeyData.KeyMaterialType.ASYMMETRIC_PUBLIC), 43, KeyStatusType.ENABLED, OutputPrefixType.RAW); KeysetHandle keysetHandlePub = TestUtil.createKeysetHandle(TestUtil.createKeyset(primaryPub, rawPub)); KeysetHandle keysetHandlePriv = TestUtil.createKeysetHandle(TestUtil.createKeyset(primaryPriv, rawPriv)); HybridEncrypt hybridEncrypt = new HybridEncryptWrapper() .wrap(Registry.getPrimitives(keysetHandlePub, HybridEncrypt.class)); HybridDecrypt hybridDecrypt = new HybridDecryptWrapper() .wrap(Registry.getPrimitives(keysetHandlePriv, HybridDecrypt.class)); byte[] plaintext = Random.randBytes(20); byte[] contextInfo = Random.randBytes(20); byte[] ciphertext = hybridEncrypt.encrypt(plaintext, contextInfo); assertArrayEquals(plaintext, hybridDecrypt.decrypt(ciphertext, contextInfo)); }
@Override public HybridEncrypt wrap(final PrimitiveSet<HybridEncrypt> primitives) { return new WrappedHybridEncrypt(primitives); }
HybridEncryptWrapper implements PrimitiveWrapper<HybridEncrypt, HybridEncrypt> { @Override public HybridEncrypt wrap(final PrimitiveSet<HybridEncrypt> primitives) { return new WrappedHybridEncrypt(primitives); } }
HybridEncryptWrapper implements PrimitiveWrapper<HybridEncrypt, HybridEncrypt> { @Override public HybridEncrypt wrap(final PrimitiveSet<HybridEncrypt> primitives) { return new WrappedHybridEncrypt(primitives); }  }
HybridEncryptWrapper implements PrimitiveWrapper<HybridEncrypt, HybridEncrypt> { @Override public HybridEncrypt wrap(final PrimitiveSet<HybridEncrypt> primitives) { return new WrappedHybridEncrypt(primitives); }  @Override HybridEncrypt wrap(final PrimitiveSet<HybridEncrypt> primitives); @Override Class<HybridEncrypt> getPrimitiveClass(); @Override Class<HybridEncrypt> getInputPrimitiveClass(); static void register(); }
HybridEncryptWrapper implements PrimitiveWrapper<HybridEncrypt, HybridEncrypt> { @Override public HybridEncrypt wrap(final PrimitiveSet<HybridEncrypt> primitives) { return new WrappedHybridEncrypt(primitives); }  @Override HybridEncrypt wrap(final PrimitiveSet<HybridEncrypt> primitives); @Override Class<HybridEncrypt> getPrimitiveClass(); @Override Class<HybridEncrypt> getInputPrimitiveClass(); static void register();  }