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));
}
}
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);
}
Aggregations