Search in sources :

Example 66 with DERBitString

use of org.bouncycastle.asn1.DERBitString in project jruby-openssl by jruby.

the class NetscapeSPKI method toDER.

private byte[] toDER() throws IOException {
    ASN1Sequence b = (ASN1Sequence) ((NetscapeCertRequest) cert).toASN1Primitive();
    ASN1ObjectIdentifier encType = (ASN1ObjectIdentifier) ((ASN1Sequence) ((ASN1Sequence) ((ASN1Sequence) b.getObjectAt(0)).getObjectAt(0)).getObjectAt(0)).getObjectAt(0);
    ASN1ObjectIdentifier sigAlg = ((AlgorithmIdentifier) b.getObjectAt(1)).getAlgorithm();
    DERBitString sig = (DERBitString) b.getObjectAt(2);
    DERBitString publicKey = new DERBitString(((PKey) public_key).to_der().convertToString().getBytes());
    DERIA5String encodedChallenge = new DERIA5String(this.challenge.toString());
    ASN1EncodableVector v1 = new ASN1EncodableVector();
    ASN1EncodableVector v1_2 = new ASN1EncodableVector();
    ASN1EncodableVector v2 = new ASN1EncodableVector();
    ASN1EncodableVector v3 = new ASN1EncodableVector();
    ASN1EncodableVector v4 = new ASN1EncodableVector();
    v4.add(encType);
    v4.add(DERNull.INSTANCE);
    v3.add(new DLSequence(v4));
    v3.add(publicKey);
    v2.add(new DLSequence(v3));
    v2.add(encodedChallenge);
    v1.add(new DLSequence(v2));
    v1_2.add(sigAlg);
    v1_2.add(DERNull.INSTANCE);
    v1.add(new DLSequence(v1_2));
    v1.add(sig);
    return new DLSequence(v1).getEncoded();
}
Also used : ASN1Sequence(org.bouncycastle.asn1.ASN1Sequence) DERIA5String(org.bouncycastle.asn1.DERIA5String) DLSequence(org.bouncycastle.asn1.DLSequence) ASN1EncodableVector(org.bouncycastle.asn1.ASN1EncodableVector) DERBitString(org.bouncycastle.asn1.DERBitString) ASN1ObjectIdentifier(org.bouncycastle.asn1.ASN1ObjectIdentifier) AlgorithmIdentifier(org.bouncycastle.asn1.x509.AlgorithmIdentifier)

Aggregations

DERBitString (org.bouncycastle.asn1.DERBitString)54 IOException (java.io.IOException)22 DERSequence (org.bouncycastle.asn1.DERSequence)19 ASN1EncodableVector (org.bouncycastle.asn1.ASN1EncodableVector)17 DERIA5String (org.bouncycastle.asn1.DERIA5String)14 ASN1Sequence (org.bouncycastle.asn1.ASN1Sequence)12 ASN1OctetString (org.bouncycastle.asn1.ASN1OctetString)11 DEROctetString (org.bouncycastle.asn1.DEROctetString)11 ASN1EncodableVector (com.android.org.bouncycastle.asn1.ASN1EncodableVector)10 DERBitString (com.android.org.bouncycastle.asn1.DERBitString)10 ASN1ObjectIdentifier (org.bouncycastle.asn1.ASN1ObjectIdentifier)9 InvalidKeyException (java.security.InvalidKeyException)7 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)7 ASN1InputStream (org.bouncycastle.asn1.ASN1InputStream)7 KeyPair (java.security.KeyPair)6 KeyPairGenerator (java.security.KeyPairGenerator)6 ArrayList (java.util.ArrayList)6 X500Principal (javax.security.auth.x500.X500Principal)6 ASN1Integer (org.bouncycastle.asn1.ASN1Integer)6 AlgorithmIdentifier (org.bouncycastle.asn1.x509.AlgorithmIdentifier)5