EciesAeadHkdfPrivateKeyManager extends PrivateKeyTypeManager<EciesAeadHkdfPrivateKey, EciesAeadHkdfPublicKey> { @Override public EciesAeadHkdfPublicKey getPublicKey(EciesAeadHkdfPrivateKey key) throws GeneralSecurityException { return key.getPublicKey(); } EciesAeadHkdfPrivateKeyManager(); @Override String getKeyType(); @Override int getVersion(); @Override EciesAeadHkdfPublicKey getPublicKey(EciesAeadHkdfPrivateKey key); @Override KeyMaterialType keyMaterialType(); @Override EciesAeadHkdfPrivateKey parseKey(ByteString byteString); @Override void validateKey(EciesAeadHkdfPrivateKey keyProto); @Override KeyFactory<EciesAeadHkdfKeyFormat, EciesAeadHkdfPrivateKey> keyFactory(); static void registerPair(boolean newKeyAllowed); static final KeyTemplate eciesP256HkdfHmacSha256Aes128GcmTemplate(); static final KeyTemplate rawEciesP256HkdfHmacSha256Aes128GcmCompressedTemplate(); static final KeyTemplate eciesP256HkdfHmacSha256Aes128CtrHmacSha256Template(); static final KeyTemplate rawEciesP256HkdfHmacSha256Aes128CtrHmacSha256CompressedTemplate();  }
@Test public void createKey_checkValues() throws Exception { EciesAeadHkdfKeyFormat format = createKeyFormat( EllipticCurveType.NIST_P256, HashType.SHA256, EcPointFormat.UNCOMPRESSED, AesCtrHmacAeadKeyManager.aes128CtrHmacSha256Template(), TestUtil.hexDecode("aabbccddeeff")); EciesAeadHkdfPrivateKey key = factory.createKey(format); assertThat(key.getPublicKey().getParams()).isEqualTo(format.getParams()); assertThat(key.getPublicKey().getX()).isNotEmpty(); assertThat(key.getPublicKey().getY()).isNotEmpty(); assertThat(key.getKeyValue()).isNotEmpty(); }
@Test public void getPublicKey_values() throws Exception { EciesAeadHkdfPrivateKey key = createValidKey(); EciesAeadHkdfPublicKey publicKey = manager.getPublicKey(key); assertThat(publicKey).isEqualTo(key.getPublicKey()); }
@Test public void createPrimitive() throws Exception { EciesAeadHkdfPrivateKey key = createValidKey(); HybridDecrypt hybridDecrypt = manager.getPrimitive(key, HybridDecrypt.class); EciesAeadHkdfParams eciesParams = key.getPublicKey().getParams(); EciesHkdfKemParams kemParams = eciesParams.getKemParams(); ECPublicKey recipientPublicKey = EllipticCurves.getEcPublicKey( HybridUtil.toCurveType(kemParams.getCurveType()), key.getPublicKey().getX().toByteArray(), key.getPublicKey().getY().toByteArray()); EciesAeadHkdfDemHelper demHelper = new RegistryEciesAeadHkdfDemHelper(eciesParams.getDemParams().getAeadDem()); HybridEncrypt hybridEncrypt = new EciesAeadHkdfHybridEncrypt( recipientPublicKey, kemParams.getHkdfSalt().toByteArray(), HybridUtil.toHmacAlgo(kemParams.getHkdfHashType()), HybridUtil.toPointFormatType(eciesParams.getEcPointFormat()), demHelper); byte[] message = Random.randBytes(20); byte[] contextInfo = Random.randBytes(20); assertThat(hybridDecrypt.decrypt(hybridEncrypt.encrypt(message, contextInfo), contextInfo)) .isEqualTo(message); }