Search in sources :

Example 1 with EciesAeadHkdfDemHelper

use of com.google.crypto.tink.subtle.EciesAeadHkdfDemHelper in project tink by google.

the class EciesAeadHkdfPrivateKeyManager method getPrimitive.

/**
 * @param recipientKey {@code EciesAeadHkdfPrivateKey} proto
 */
@Override
public HybridDecrypt getPrimitive(MessageLite recipientKey) throws GeneralSecurityException {
    if (!(recipientKey instanceof EciesAeadHkdfPrivateKey)) {
        throw new GeneralSecurityException("expected EciesAeadHkdfPrivateKey proto");
    }
    EciesAeadHkdfPrivateKey recipientKeyProto = (EciesAeadHkdfPrivateKey) recipientKey;
    validate(recipientKeyProto);
    EciesAeadHkdfParams eciesParams = recipientKeyProto.getPublicKey().getParams();
    EciesHkdfKemParams kemParams = eciesParams.getKemParams();
    ECPrivateKey recipientPrivateKey = EllipticCurves.getEcPrivateKey(HybridUtil.toCurveType(kemParams.getCurveType()), recipientKeyProto.getKeyValue().toByteArray());
    EciesAeadHkdfDemHelper demHelper = new RegistryEciesAeadHkdfDemHelper(eciesParams.getDemParams().getAeadDem());
    return new EciesAeadHkdfHybridDecrypt(recipientPrivateKey, kemParams.getHkdfSalt().toByteArray(), HybridUtil.toHmacAlgo(kemParams.getHkdfHashType()), HybridUtil.toPointFormatType(eciesParams.getEcPointFormat()), demHelper);
}
Also used : EciesAeadHkdfDemHelper(com.google.crypto.tink.subtle.EciesAeadHkdfDemHelper) EciesAeadHkdfParams(com.google.crypto.tink.proto.EciesAeadHkdfParams) ECPrivateKey(java.security.interfaces.ECPrivateKey) EciesAeadHkdfHybridDecrypt(com.google.crypto.tink.subtle.EciesAeadHkdfHybridDecrypt) EciesAeadHkdfPrivateKey(com.google.crypto.tink.proto.EciesAeadHkdfPrivateKey) GeneralSecurityException(java.security.GeneralSecurityException) EciesHkdfKemParams(com.google.crypto.tink.proto.EciesHkdfKemParams)

Example 2 with EciesAeadHkdfDemHelper

use of com.google.crypto.tink.subtle.EciesAeadHkdfDemHelper 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);
}
Also used : EciesAeadHkdfDemHelper(com.google.crypto.tink.subtle.EciesAeadHkdfDemHelper) EciesAeadHkdfParams(com.google.crypto.tink.proto.EciesAeadHkdfParams) ECPublicKey(java.security.interfaces.ECPublicKey) GeneralSecurityException(java.security.GeneralSecurityException) EciesAeadHkdfPublicKey(com.google.crypto.tink.proto.EciesAeadHkdfPublicKey) EciesHkdfKemParams(com.google.crypto.tink.proto.EciesHkdfKemParams) EciesAeadHkdfHybridEncrypt(com.google.crypto.tink.subtle.EciesAeadHkdfHybridEncrypt)

Aggregations

EciesAeadHkdfParams (com.google.crypto.tink.proto.EciesAeadHkdfParams)2 EciesHkdfKemParams (com.google.crypto.tink.proto.EciesHkdfKemParams)2 EciesAeadHkdfDemHelper (com.google.crypto.tink.subtle.EciesAeadHkdfDemHelper)2 GeneralSecurityException (java.security.GeneralSecurityException)2 EciesAeadHkdfPrivateKey (com.google.crypto.tink.proto.EciesAeadHkdfPrivateKey)1 EciesAeadHkdfPublicKey (com.google.crypto.tink.proto.EciesAeadHkdfPublicKey)1 EciesAeadHkdfHybridDecrypt (com.google.crypto.tink.subtle.EciesAeadHkdfHybridDecrypt)1 EciesAeadHkdfHybridEncrypt (com.google.crypto.tink.subtle.EciesAeadHkdfHybridEncrypt)1 ECPrivateKey (java.security.interfaces.ECPrivateKey)1 ECPublicKey (java.security.interfaces.ECPublicKey)1