Search in sources :

Example 21 with DEROutputStream

use of org.gudy.bouncycastle.asn1.DEROutputStream in project BiglyBT by BiglySoftware.

the class X509CertificateObject method getExtensionValue.

@Override
public byte[] getExtensionValue(String oid) {
    X509Extensions exts = c.getTBSCertificate().getExtensions();
    if (exts != null) {
        X509Extension ext = exts.getExtension(new DERObjectIdentifier(oid));
        if (ext != null) {
            ByteArrayOutputStream bOut = new ByteArrayOutputStream();
            DEROutputStream dOut = new DEROutputStream(bOut);
            try {
                dOut.writeObject(ext.getValue());
                return bOut.toByteArray();
            } catch (Exception e) {
                throw new RuntimeException("error encoding " + e.toString());
            }
        }
    }
    return null;
}
Also used : X509Extension(org.gudy.bouncycastle.asn1.x509.X509Extension) ByteArrayOutputStream(java.io.ByteArrayOutputStream) IOException(java.io.IOException)

Example 22 with DEROutputStream

use of org.gudy.bouncycastle.asn1.DEROutputStream in project BiglyBT by BiglySoftware.

the class X509Principal method getEncoded.

/**
 * return a DER encoded byte array representing this object
 */
@Override
public byte[] getEncoded() {
    ByteArrayOutputStream bOut = new ByteArrayOutputStream();
    DEROutputStream dOut = new DEROutputStream(bOut);
    try {
        dOut.writeObject(this);
    } catch (IOException e) {
        throw new RuntimeException(e.toString());
    }
    return bOut.toByteArray();
}
Also used : ByteArrayOutputStream(java.io.ByteArrayOutputStream) IOException(java.io.IOException) DEROutputStream(org.gudy.bouncycastle.asn1.DEROutputStream)

Example 23 with DEROutputStream

use of org.gudy.bouncycastle.asn1.DEROutputStream in project BiglyBT by BiglySoftware.

the class JCERSAPublicKey method getEncoded.

@Override
public byte[] getEncoded() {
    ByteArrayOutputStream bOut = new ByteArrayOutputStream();
    DEROutputStream dOut = new DEROutputStream(bOut);
    SubjectPublicKeyInfo info = new SubjectPublicKeyInfo(new AlgorithmIdentifier(PKCSObjectIdentifiers.rsaEncryption, new DERNull()), new RSAPublicKeyStructure(getModulus(), getPublicExponent()).getDERObject());
    try {
        dOut.writeObject(info);
        dOut.close();
    } catch (IOException e) {
        throw new RuntimeException("Error encoding RSA public key");
    }
    return bOut.toByteArray();
}
Also used : RSAPublicKeyStructure(org.gudy.bouncycastle.asn1.x509.RSAPublicKeyStructure) DERNull(org.gudy.bouncycastle.asn1.DERNull) ByteArrayOutputStream(java.io.ByteArrayOutputStream) IOException(java.io.IOException) SubjectPublicKeyInfo(org.gudy.bouncycastle.asn1.x509.SubjectPublicKeyInfo) DEROutputStream(org.gudy.bouncycastle.asn1.DEROutputStream) AlgorithmIdentifier(org.gudy.bouncycastle.asn1.x509.AlgorithmIdentifier)

Example 24 with DEROutputStream

use of org.gudy.bouncycastle.asn1.DEROutputStream in project pdfbox by apache.

the class PublicKeySecurityHandler method computeRecipientsField.

private byte[][] computeRecipientsField(byte[] seed) throws GeneralSecurityException, IOException {
    byte[][] recipientsField = new byte[policy.getNumberOfRecipients()][];
    Iterator<PublicKeyRecipient> it = policy.getRecipientsIterator();
    int i = 0;
    while (it.hasNext()) {
        PublicKeyRecipient recipient = it.next();
        X509Certificate certificate = recipient.getX509();
        int permission = recipient.getPermission().getPermissionBytesForPublicKey();
        byte[] pkcs7input = new byte[24];
        byte one = (byte) (permission);
        byte two = (byte) (permission >>> 8);
        byte three = (byte) (permission >>> 16);
        byte four = (byte) (permission >>> 24);
        // put this seed in the pkcs7 input
        System.arraycopy(seed, 0, pkcs7input, 0, 20);
        pkcs7input[20] = four;
        pkcs7input[21] = three;
        pkcs7input[22] = two;
        pkcs7input[23] = one;
        ASN1Primitive obj = createDERForRecipient(pkcs7input, certificate);
        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        DEROutputStream derOS = new DEROutputStream(baos);
        derOS.writeObject(obj);
        recipientsField[i] = baos.toByteArray();
        i++;
    }
    return recipientsField;
}
Also used : ByteArrayOutputStream(java.io.ByteArrayOutputStream) ASN1Primitive(org.bouncycastle.asn1.ASN1Primitive) X509Certificate(java.security.cert.X509Certificate) DEROutputStream(org.bouncycastle.asn1.DEROutputStream)

Example 25 with DEROutputStream

use of org.gudy.bouncycastle.asn1.DEROutputStream in project atlas by alibaba.

the class LocalSignedJarBuilder method writeSignatureBlock.

/**
 * Write the certificate file with a digital signature.
 */
private void writeSignatureBlock(CMSTypedData data, X509Certificate publicKey, PrivateKey privateKey) throws IOException, CertificateEncodingException, OperatorCreationException, CMSException {
    ArrayList<X509Certificate> certList = new ArrayList<X509Certificate>();
    certList.add(publicKey);
    JcaCertStore certs = new JcaCertStore(certList);
    CMSSignedDataGenerator gen = new CMSSignedDataGenerator();
    ContentSigner sha1Signer = new JcaContentSignerBuilder("SHA1with" + privateKey.getAlgorithm()).build(privateKey);
    gen.addSignerInfoGenerator(new JcaSignerInfoGeneratorBuilder(new JcaDigestCalculatorProviderBuilder().build()).setDirectSignature(true).build(sha1Signer, publicKey));
    gen.addCertificates(certs);
    CMSSignedData sigData = gen.generate(data, false);
    ASN1InputStream asn1 = new ASN1InputStream(sigData.getEncoded());
    DEROutputStream dos = new DEROutputStream(mOutputJar);
    dos.writeObject(asn1.readObject());
    dos.flush();
    dos.close();
    asn1.close();
}
Also used : CMSSignedDataGenerator(org.bouncycastle.cms.CMSSignedDataGenerator) ASN1InputStream(org.bouncycastle.asn1.ASN1InputStream) JcaSignerInfoGeneratorBuilder(org.bouncycastle.cms.jcajce.JcaSignerInfoGeneratorBuilder) JcaContentSignerBuilder(org.bouncycastle.operator.jcajce.JcaContentSignerBuilder) ArrayList(java.util.ArrayList) ContentSigner(org.bouncycastle.operator.ContentSigner) JcaCertStore(org.bouncycastle.cert.jcajce.JcaCertStore) JcaDigestCalculatorProviderBuilder(org.bouncycastle.operator.jcajce.JcaDigestCalculatorProviderBuilder) CMSSignedData(org.bouncycastle.cms.CMSSignedData) X509Certificate(java.security.cert.X509Certificate) DEROutputStream(org.bouncycastle.asn1.DEROutputStream)

Aggregations

ByteArrayOutputStream (java.io.ByteArrayOutputStream)20 IOException (java.io.IOException)20 DEROutputStream (org.bouncycastle.asn1.DEROutputStream)13 DEROutputStream (org.gudy.bouncycastle.asn1.DEROutputStream)9 X509Certificate (java.security.cert.X509Certificate)7 OutputStream (java.io.OutputStream)4 AlgorithmIdentifier (org.gudy.bouncycastle.asn1.x509.AlgorithmIdentifier)4 CertificateException (java.security.cert.CertificateException)3 ASN1EncodableVector (org.bouncycastle.asn1.ASN1EncodableVector)3 ASN1InputStream (org.bouncycastle.asn1.ASN1InputStream)3 DEROctetString (org.bouncycastle.asn1.DEROctetString)3 DERSequence (org.bouncycastle.asn1.DERSequence)3 JcaCertStore (org.bouncycastle.cert.jcajce.JcaCertStore)3 CMSSignedData (org.bouncycastle.cms.CMSSignedData)3 CMSSignedDataGenerator (org.bouncycastle.cms.CMSSignedDataGenerator)3 ContentSigner (org.bouncycastle.operator.ContentSigner)3 JcaContentSignerBuilder (org.bouncycastle.operator.jcajce.JcaContentSignerBuilder)3 JcaDigestCalculatorProviderBuilder (org.bouncycastle.operator.jcajce.JcaDigestCalculatorProviderBuilder)3 X509Extension (org.gudy.bouncycastle.asn1.x509.X509Extension)3 KeyStoreException (java.security.KeyStoreException)2