use of com.google.crypto.tink.proto.EciesAeadHkdfParams in project tink by google.
the class EciesAeadHkdfPublicKeyManager method getPrimitive.
/**
* @param recipientKey {@code EciesAeadHkdfPublicKey} proto
*/
@Override
public HybridEncrypt getPrimitive(MessageLite recipientKey) throws GeneralSecurityException {
if (!(recipientKey instanceof EciesAeadHkdfPublicKey)) {
throw new GeneralSecurityException("expected EciesAeadHkdfPublicKey proto");
}
EciesAeadHkdfPublicKey recipientKeyProto = (EciesAeadHkdfPublicKey) recipientKey;
validate(recipientKeyProto);
EciesAeadHkdfParams eciesParams = recipientKeyProto.getParams();
EciesHkdfKemParams kemParams = eciesParams.getKemParams();
ECPublicKey recipientPublicKey = EllipticCurves.getEcPublicKey(HybridUtil.toCurveType(kemParams.getCurveType()), recipientKeyProto.getX().toByteArray(), recipientKeyProto.getY().toByteArray());
EciesAeadHkdfDemHelper demHelper = new RegistryEciesAeadHkdfDemHelper(eciesParams.getDemParams().getAeadDem());
return new EciesAeadHkdfHybridEncrypt(recipientPublicKey, kemParams.getHkdfSalt().toByteArray(), HybridUtil.toHmacAlgo(kemParams.getHkdfHashType()), HybridUtil.toPointFormatType(eciesParams.getEcPointFormat()), demHelper);
}
use of com.google.crypto.tink.proto.EciesAeadHkdfParams in project tink by google.
the class EciesAeadHkdfPublicKeyManagerTest method createKeyFormat.
private EciesAeadHkdfKeyFormat createKeyFormat(EllipticCurveType curve, HashType hashType, EcPointFormat ecPointFormat, KeyTemplate demKeyTemplate, byte[] salt) {
EciesHkdfKemParams kemParams = EciesHkdfKemParams.newBuilder().setCurveType(curve).setHkdfHashType(hashType).setHkdfSalt(ByteString.copyFrom(salt)).build();
EciesAeadDemParams demParams = EciesAeadDemParams.newBuilder().setAeadDem(demKeyTemplate).build();
EciesAeadHkdfParams params = EciesAeadHkdfParams.newBuilder().setKemParams(kemParams).setDemParams(demParams).setEcPointFormat(ecPointFormat).build();
return EciesAeadHkdfKeyFormat.newBuilder().setParams(params).build();
}
Aggregations