use of com.unboundid.asn1.ASN1Set in project jruby-openssl by jruby.
the class Envelope method fromASN1.
/**
* EnvelopedData ::= SEQUENCE {
* version Version,
* recipientInfos RecipientInfos,
* encryptedContentInfo EncryptedContentInfo }
*
* Version ::= INTEGER
*
* RecipientInfos ::= SET OF RecipientInfo
*/
public static Envelope fromASN1(ASN1Encodable content) {
ASN1Sequence sequence = (ASN1Sequence) content;
ASN1Integer version = (ASN1Integer) sequence.getObjectAt(0);
ASN1Set recipients = (ASN1Set) sequence.getObjectAt(1);
ASN1Encodable encContent = sequence.getObjectAt(2);
Envelope envelope = new Envelope();
envelope.setVersion(version.getValue().intValue());
envelope.setRecipientInfo(recipientInfosFromASN1Set(recipients));
envelope.setEncData(EncContent.fromASN1(encContent));
return envelope;
}
use of com.unboundid.asn1.ASN1Set in project LinLong-Java by zhenwei1108.
the class CMSAuthEnvelopedDataGenerator method doGenerate.
private CMSAuthEnvelopedData doGenerate(CMSTypedData content, OutputAEADEncryptor contentEncryptor) throws CMSException {
ASN1EncodableVector recipientInfos = new ASN1EncodableVector();
AlgorithmIdentifier encAlgId;
ASN1OctetString encContent;
ByteArrayOutputStream bOut = new ByteArrayOutputStream();
ASN1Set authenticatedAttrSet = null;
try {
OutputStream cOut = contentEncryptor.getOutputStream(bOut);
content.write(cOut);
if (authAttrsGenerator != null) {
AttributeTable attrTable = authAttrsGenerator.getAttributes(Collections.EMPTY_MAP);
authenticatedAttrSet = new DERSet(attrTable.toASN1EncodableVector());
contentEncryptor.getAADStream().write(authenticatedAttrSet.getEncoded(ASN1Encoding.DER));
}
cOut.close();
} catch (IOException e) {
throw new CMSException("unable to process authenticated content: " + e.getMessage(), e);
}
byte[] encryptedContent = bOut.toByteArray();
byte[] mac = contentEncryptor.getMAC();
encAlgId = contentEncryptor.getAlgorithmIdentifier();
encContent = new BEROctetString(encryptedContent);
GenericKey encKey = contentEncryptor.getKey();
for (Iterator it = recipientInfoGenerators.iterator(); it.hasNext(); ) {
RecipientInfoGenerator recipient = (RecipientInfoGenerator) it.next();
recipientInfos.add(recipient.generate(encKey));
}
EncryptedContentInfo eci = new EncryptedContentInfo(content.getContentType(), encAlgId, encContent);
ASN1Set unprotectedAttrSet = null;
if (unauthAttrsGenerator != null) {
AttributeTable attrTable = unauthAttrsGenerator.getAttributes(Collections.EMPTY_MAP);
unprotectedAttrSet = new DLSet(attrTable.toASN1EncodableVector());
}
ContentInfo contentInfo = new ContentInfo(CMSObjectIdentifiers.authEnvelopedData, new AuthEnvelopedData(originatorInfo, new DERSet(recipientInfos), eci, authenticatedAttrSet, new DEROctetString(mac), unprotectedAttrSet));
return new CMSAuthEnvelopedData(contentInfo);
}
use of com.unboundid.asn1.ASN1Set in project LinLong-Java by zhenwei1108.
the class PKCS10CertificationRequest method getAttributes.
/**
* Return an array of attributes matching the passed in type OID.
*
* @param type the type of the attribute being looked for.
* @return an array of Attribute of the requested type, zero length if none present.
*/
public Attribute[] getAttributes(ASN1ObjectIdentifier type) {
ASN1Set attrSet = certificationRequest.getCertificationRequestInfo().getAttributes();
if (attrSet == null) {
return EMPTY_ARRAY;
}
List list = new ArrayList();
for (int i = 0; i != attrSet.size(); i++) {
Attribute attr = Attribute.getInstance(attrSet.getObjectAt(i));
if (attr.getAttrType().equals(type)) {
list.add(attr);
}
}
if (list.size() == 0) {
return EMPTY_ARRAY;
}
return (Attribute[]) list.toArray(new Attribute[list.size()]);
}
use of com.unboundid.asn1.ASN1Set in project LinLong-Java by zhenwei1108.
the class PKCS10CertificationRequest method getAttributes.
/**
* Return the attributes, if any associated with this request.
*
* @return an array of Attribute, zero length if none present.
*/
public Attribute[] getAttributes() {
ASN1Set attrSet = certificationRequest.getCertificationRequestInfo().getAttributes();
if (attrSet == null) {
return EMPTY_ARRAY;
}
Attribute[] attrs = new Attribute[attrSet.size()];
for (int i = 0; i != attrSet.size(); i++) {
attrs[i] = Attribute.getInstance(attrSet.getObjectAt(i));
}
return attrs;
}
use of com.unboundid.asn1.ASN1Set in project LinLong-Java by zhenwei1108.
the class BCEdDSAPrivateKey method getEncoded.
public byte[] getEncoded() {
try {
ASN1Set attrSet = ASN1Set.getInstance(attributes);
PrivateKeyInfo privInfo = PrivateKeyInfoFactory.createPrivateKeyInfo(eddsaPrivateKey, attrSet);
if (hasPublicKey && !Properties.isOverrideSet("com.github.zhenwei.pkix.pkcs8.v1_info_only")) {
return privInfo.getEncoded();
} else {
return new PrivateKeyInfo(privInfo.getPrivateKeyAlgorithm(), privInfo.parsePrivateKey(), attrSet).getEncoded();
}
} catch (IOException e) {
return null;
}
}
Aggregations