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); }
public RecipientInfo generate(GenericKey contentEncryptionKey) throws CMSException { OriginatorIdentifierOrKey originator = new OriginatorIdentifierOrKey( createOriginatorPublicKey(originatorKeyInfo)); ASN1EncodableVector params = new ASN1EncodableVector(); params.add(keyEncryptionOID); params.add(DERNull.INSTANCE); AlgorithmIdentifier keyEncAlg = new AlgorithmIdentifier(keyEncryptionOID, DERNull.INSTANCE); AlgorithmIdentifier keyAgreeAlg = new AlgorithmIdentifier(keyAgreementOID, keyEncAlg); ASN1Sequence recipients = generateRecipientEncryptedKeys(keyAgreeAlg, keyEncAlg, contentEncryptionKey); ASN1Encodable userKeyingMaterial = getUserKeyingMaterial(keyAgreeAlg); if (userKeyingMaterial != null) { try { return new RecipientInfo(new KeyAgreeRecipientInfo(originator, new DEROctetString(userKeyingMaterial), keyAgreeAlg, recipients)); } catch (IOException e) { throw new CMSException("unable to encode userKeyingMaterial: " + e.getMessage(), e); } } else { return new RecipientInfo(new KeyAgreeRecipientInfo(originator, null, keyAgreeAlg, recipients)); } }
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 { 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)); } }