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;
}
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();
}
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();
}
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;
}
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();
}
Aggregations