use of org.spongycastle.asn1.DLSequence in project jruby-openssl by jruby.
the class PKCS7 method sign.
/* c: PKCS7_sign
*
*/
public static PKCS7 sign(X509AuxCertificate signcert, PrivateKey pkey, Collection<X509AuxCertificate> certs, BIO data, int flags) throws PKCS7Exception {
PKCS7 p7 = new PKCS7();
p7.setType(ASN1Registry.NID_pkcs7_signed);
p7.contentNew(ASN1Registry.NID_pkcs7_data);
SignerInfoWithPkey si = p7.addSignature(signcert, pkey, EVP.sha1());
if ((flags & NOCERTS) == 0) {
p7.addCertificate(signcert);
if (certs != null) {
for (X509AuxCertificate c : certs) {
p7.addCertificate(c);
}
}
}
if ((flags & NOATTR) == 0) {
si.addSignedAttribute(ASN1Registry.NID_pkcs9_contentType, OID_pkcs7_data);
if ((flags & NOSMIMECAP) == 0) {
ASN1EncodableVector smcap = new ASN1EncodableVector();
smcap.add(new AlgorithmIdentifier(OID_des_ede3_cbc));
smcap.add(new AlgorithmIdentifier(OID_rc2_cbc, new ASN1Integer(BI_128)));
smcap.add(new AlgorithmIdentifier(OID_rc2_cbc, new ASN1Integer(BI_64)));
smcap.add(new AlgorithmIdentifier(OID_rc2_cbc, new ASN1Integer(BI_40)));
smcap.add(new AlgorithmIdentifier(OID_des_cbc));
si.addSignedAttribute(ASN1Registry.NID_SMIMECapabilities, new DLSequence(smcap));
}
}
if ((flags & STREAM) != 0) {
return p7;
}
BIO p7bio = p7.dataInit(null);
try {
data.crlfCopy(p7bio, flags);
} catch (IOException e) {
throw new PKCS7Exception(F_PKCS7_SIGN, R_PKCS7_DATAFINAL_ERROR, e);
}
if ((flags & DETACHED) != 0) {
p7.setDetached(1);
}
p7.dataFinal(p7bio);
return p7;
}
use of org.spongycastle.asn1.DLSequence in project jruby-openssl by jruby.
the class PKCS7 method asASN1.
public ASN1Encodable asASN1() {
ASN1EncodableVector vector = new ASN1EncodableVector();
ASN1ObjectIdentifier contentType;
if (data == null) {
// OpenSSL behavior
contentType = new ASN1ObjectIdentifier(EMPTY_PKCS7_OID);
} else {
contentType = ASN1Registry.nid2obj(getType());
}
vector.add(contentType);
if (data != null) {
vector.add(new DERTaggedObject(0, data.asASN1()));
}
return new DLSequence(vector);
}
use of org.spongycastle.asn1.DLSequence in project jruby-openssl by jruby.
the class PKey method toDerDSAKey.
public static byte[] toDerDSAKey(DSAPublicKey pubKey, DSAPrivateKey privKey) throws IOException {
if (pubKey != null && privKey == null) {
return pubKey.getEncoded();
}
if (privKey != null && pubKey != null) {
ASN1EncodableVector vec = new ASN1EncodableVector();
final DSAParams params = privKey.getParams();
vec.add(new ASN1Integer(BigInteger.ZERO));
vec.add(new ASN1Integer(params.getP()));
vec.add(new ASN1Integer(params.getQ()));
vec.add(new ASN1Integer(params.getG()));
vec.add(new ASN1Integer(pubKey.getY()));
vec.add(new ASN1Integer(privKey.getX()));
return new DLSequence(vec).getEncoded();
}
if (privKey == null) {
throw new IllegalArgumentException("private key as well as public key are null");
}
return privKey.getEncoded();
}
use of org.spongycastle.asn1.DLSequence in project jruby-openssl by jruby.
the class SignerInfoWithPkey method toASN1Object.
/**
* Produce an object suitable for an ASN1OutputStream.
* <pre>
* SignerInfo ::= SEQUENCE {
* version Version,
* issuerAndSerialNumber IssuerAndSerialNumber,
* digestAlgorithm DigestAlgorithmIdentifier,
* authenticatedAttributes [0] IMPLICIT Attributes OPTIONAL,
* digestEncryptionAlgorithm DigestEncryptionAlgorithmIdentifier,
* encryptedDigest EncryptedDigest,
* unauthenticatedAttributes [1] IMPLICIT Attributes OPTIONAL
* }
*
* EncryptedDigest ::= OCTET STRING
*
* DigestAlgorithmIdentifier ::= AlgorithmIdentifier
*
* DigestEncryptionAlgorithmIdentifier ::= AlgorithmIdentifier
* </pre>
*/
public ASN1Encodable toASN1Object() {
ASN1EncodableVector v = new ASN1EncodableVector();
v.add(version);
v.add(issuerAndSerialNumber);
v.add(digAlgorithm);
if (authenticatedAttributes != null) {
v.add(new DERTaggedObject(false, 0, authenticatedAttributes));
}
v.add(digEncryptionAlgorithm);
v.add(encryptedDigest);
if (unauthenticatedAttributes != null) {
v.add(new DERTaggedObject(false, 1, unauthenticatedAttributes));
}
return new DLSequence(v);
}
use of org.spongycastle.asn1.DLSequence in project jruby-openssl by jruby.
the class Envelope method asASN1.
public ASN1Encodable asASN1() {
ASN1EncodableVector vector = new ASN1EncodableVector();
vector.add(new ASN1Integer(BigInteger.valueOf(version)));
vector.add(receipientInfosToASN1Set());
vector.add(encData.asASN1());
return new DLSequence(vector);
}
Aggregations