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