Search in sources :

Example 1 with KeyAgreeRecipientInfo

use of com.github.zhenwei.pkix.util.asn1.cms.KeyAgreeRecipientInfo 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 KeyAgreeRecipientInfo

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

the class KeyAgreeRecipientInformation method readRecipientInfo.

static void readRecipientInfo(List infos, KeyAgreeRecipientInfo info, AlgorithmIdentifier messageAlgorithm, CMSSecureReadable secureReadable, AuthAttributesProvider additionalData) {
    ASN1Sequence s = info.getRecipientEncryptedKeys();
    for (int i = 0; i < s.size(); ++i) {
        RecipientEncryptedKey id = RecipientEncryptedKey.getInstance(s.getObjectAt(i));
        RecipientId rid;
        KeyAgreeRecipientIdentifier karid = id.getIdentifier();
        IssuerAndSerialNumber iAndSN = karid.getIssuerAndSerialNumber();
        if (iAndSN != null) {
            rid = new KeyAgreeRecipientId(iAndSN.getName(), iAndSN.getSerialNumber().getValue());
        } else {
            RecipientKeyIdentifier rKeyID = karid.getRKeyID();
            // Note: 'date' and 'other' fields of RecipientKeyIdentifier appear to be only informational
            rid = new KeyAgreeRecipientId(rKeyID.getSubjectKeyIdentifier().getOctets());
        }
        infos.add(new KeyAgreeRecipientInformation(info, rid, id.getEncryptedKey(), messageAlgorithm, secureReadable, additionalData));
    }
}
Also used : IssuerAndSerialNumber(com.github.zhenwei.pkix.util.asn1.cms.IssuerAndSerialNumber) ASN1Sequence(com.github.zhenwei.core.asn1.ASN1Sequence) RecipientEncryptedKey(com.github.zhenwei.pkix.util.asn1.cms.RecipientEncryptedKey) RecipientKeyIdentifier(com.github.zhenwei.pkix.util.asn1.cms.RecipientKeyIdentifier) KeyAgreeRecipientIdentifier(com.github.zhenwei.pkix.util.asn1.cms.KeyAgreeRecipientIdentifier)

Aggregations

ASN1Sequence (com.github.zhenwei.core.asn1.ASN1Sequence)2 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 IssuerAndSerialNumber (com.github.zhenwei.pkix.util.asn1.cms.IssuerAndSerialNumber)1 KeyAgreeRecipientIdentifier (com.github.zhenwei.pkix.util.asn1.cms.KeyAgreeRecipientIdentifier)1 KeyAgreeRecipientInfo (com.github.zhenwei.pkix.util.asn1.cms.KeyAgreeRecipientInfo)1 OriginatorIdentifierOrKey (com.github.zhenwei.pkix.util.asn1.cms.OriginatorIdentifierOrKey)1 RecipientEncryptedKey (com.github.zhenwei.pkix.util.asn1.cms.RecipientEncryptedKey)1 RecipientInfo (com.github.zhenwei.pkix.util.asn1.cms.RecipientInfo)1 RecipientKeyIdentifier (com.github.zhenwei.pkix.util.asn1.cms.RecipientKeyIdentifier)1