Search in sources :

Example 1 with OriginatorIdentifierOrKey

use of com.github.zhenwei.pkix.util.asn1.cms.OriginatorIdentifierOrKey in project LinLong-Java by zhenwei1108.

the class KeyAgreeRecipientInfoGenerator method generate.

public RecipientInfo generate(GenericKey contentEncryptionKey) throws CMSException {
    OriginatorIdentifierOrKey originator = new OriginatorIdentifierOrKey(createOriginatorPublicKey(originatorKeyInfo));
    AlgorithmIdentifier keyEncAlg;
    if (CMSUtils.isDES(keyEncryptionOID.getId()) || keyEncryptionOID.equals(PKCSObjectIdentifiers.id_alg_CMSRC2wrap)) {
        keyEncAlg = new AlgorithmIdentifier(keyEncryptionOID, DERNull.INSTANCE);
    } else if (CMSUtils.isGOST(keyAgreementOID)) {
        keyEncAlg = new AlgorithmIdentifier(keyEncryptionOID, new Gost2814789KeyWrapParameters(CryptoProObjectIdentifiers.id_Gost28147_89_CryptoPro_A_ParamSet));
    } else {
        keyEncAlg = new AlgorithmIdentifier(keyEncryptionOID);
    }
    AlgorithmIdentifier keyAgreeAlg = new AlgorithmIdentifier(keyAgreementOID, keyEncAlg);
    ASN1Sequence recipients = generateRecipientEncryptedKeys(keyAgreeAlg, keyEncAlg, contentEncryptionKey);
    byte[] userKeyingMaterial = getUserKeyingMaterial(keyAgreeAlg);
    if (userKeyingMaterial != null) {
        return new RecipientInfo(new KeyAgreeRecipientInfo(originator, new DEROctetString(userKeyingMaterial), keyAgreeAlg, recipients));
    } else {
        return new RecipientInfo(new KeyAgreeRecipientInfo(originator, null, keyAgreeAlg, recipients));
    }
}
Also used : ASN1Sequence(com.github.zhenwei.core.asn1.ASN1Sequence) OriginatorIdentifierOrKey(com.github.zhenwei.pkix.util.asn1.cms.OriginatorIdentifierOrKey) Gost2814789KeyWrapParameters(com.github.zhenwei.core.asn1.cryptopro.Gost2814789KeyWrapParameters) RecipientInfo(com.github.zhenwei.pkix.util.asn1.cms.RecipientInfo) KeyAgreeRecipientInfo(com.github.zhenwei.pkix.util.asn1.cms.KeyAgreeRecipientInfo) DEROctetString(com.github.zhenwei.core.asn1.DEROctetString) AlgorithmIdentifier(com.github.zhenwei.core.asn1.x509.AlgorithmIdentifier) KeyAgreeRecipientInfo(com.github.zhenwei.pkix.util.asn1.cms.KeyAgreeRecipientInfo)

Example 2 with OriginatorIdentifierOrKey

use of com.github.zhenwei.pkix.util.asn1.cms.OriginatorIdentifierOrKey in project LinLong-Java by zhenwei1108.

the class KeyAgreeRecipientInformation method getSenderPublicKeyInfo.

private SubjectPublicKeyInfo getSenderPublicKeyInfo(AlgorithmIdentifier recKeyAlgId, OriginatorIdentifierOrKey originator) throws CMSException, IOException {
    OriginatorPublicKey opk = originator.getOriginatorKey();
    if (opk != null) {
        return getPublicKeyInfoFromOriginatorPublicKey(recKeyAlgId, opk);
    }
    OriginatorId origID;
    IssuerAndSerialNumber iAndSN = originator.getIssuerAndSerialNumber();
    if (iAndSN != null) {
        origID = new OriginatorId(iAndSN.getName(), iAndSN.getSerialNumber().getValue());
    } else {
        SubjectKeyIdentifier ski = originator.getSubjectKeyIdentifier();
        origID = new OriginatorId(ski.getKeyIdentifier());
    }
    return getPublicKeyInfoFromOriginatorId(origID);
}
Also used : IssuerAndSerialNumber(com.github.zhenwei.pkix.util.asn1.cms.IssuerAndSerialNumber) SubjectKeyIdentifier(com.github.zhenwei.core.asn1.x509.SubjectKeyIdentifier) OriginatorPublicKey(com.github.zhenwei.pkix.util.asn1.cms.OriginatorPublicKey)

Aggregations

ASN1Sequence (com.github.zhenwei.core.asn1.ASN1Sequence)1 DEROctetString (com.github.zhenwei.core.asn1.DEROctetString)1 Gost2814789KeyWrapParameters (com.github.zhenwei.core.asn1.cryptopro.Gost2814789KeyWrapParameters)1 AlgorithmIdentifier (com.github.zhenwei.core.asn1.x509.AlgorithmIdentifier)1 SubjectKeyIdentifier (com.github.zhenwei.core.asn1.x509.SubjectKeyIdentifier)1 IssuerAndSerialNumber (com.github.zhenwei.pkix.util.asn1.cms.IssuerAndSerialNumber)1 KeyAgreeRecipientInfo (com.github.zhenwei.pkix.util.asn1.cms.KeyAgreeRecipientInfo)1 OriginatorIdentifierOrKey (com.github.zhenwei.pkix.util.asn1.cms.OriginatorIdentifierOrKey)1 OriginatorPublicKey (com.github.zhenwei.pkix.util.asn1.cms.OriginatorPublicKey)1 RecipientInfo (com.github.zhenwei.pkix.util.asn1.cms.RecipientInfo)1