use of org.bouncycastle.asn1.DLSequence in project jruby-openssl by jruby.
the class X509Attribute method toASN1.
ASN1Primitive toASN1(final ThreadContext context) {
ASN1EncodableVector v1 = new ASN1EncodableVector();
v1.add(getTypeID());
if (value instanceof ASN1.Constructive) {
v1.add(((ASN1.Constructive) value).toASN1(context));
} else {
ASN1EncodableVector v2 = new ASN1EncodableVector();
v2.add(((ASN1.ASN1Data) value).toASN1(context));
v1.add(new DERSet(v2));
}
return new DLSequence(v1);
}
use of org.bouncycastle.asn1.DLSequence in project jruby-openssl by jruby.
the class X509Extension method toASN1Sequence.
ASN1Sequence toASN1Sequence() throws IOException {
final ASN1EncodableVector vec = new ASN1EncodableVector();
vec.add(getRealObjectID());
if (critical)
vec.add(DERBoolean.TRUE);
vec.add(new DEROctetString(getRealValueEncoded()));
return new DLSequence(vec);
}
use of org.bouncycastle.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.bouncycastle.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.bouncycastle.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();
}
Aggregations