use of org.jruby.ext.openssl.util.ByteArrayOutputStream in project jruby-openssl by jruby.
the class PEMInputOutput method writeDHParameters.
public static void writeDHParameters(Writer _out, DHParameterSpec params) throws IOException {
final BufferedWriter out = makeBuffered(_out);
ASN1EncodableVector v = new ASN1EncodableVector();
BigInteger value;
if ((value = params.getP()) != null) {
v.add(new ASN1Integer(value));
}
if ((value = params.getG()) != null) {
v.add(new ASN1Integer(value));
}
ByteArrayOutputStream bOut = new ByteArrayOutputStream();
ASN1OutputStream aOut = new ASN1OutputStream(bOut);
aOut.writeObject(new DLSequence(v));
out.write(BEF_G);
out.write(PEM_STRING_DHPARAMS);
out.write(AFT);
out.newLine();
writeEncoded(out, bOut.buffer(), bOut.size());
out.write(BEF_E);
out.write(PEM_STRING_DHPARAMS);
out.write(AFT);
out.newLine();
out.flush();
}
use of org.jruby.ext.openssl.util.ByteArrayOutputStream in project jruby-openssl by jruby.
the class PEMInputOutput method writeX509Aux.
public static void writeX509Aux(final Writer _out, final X509AuxCertificate cert) throws IOException {
BufferedWriter out = makeBuffered(_out);
final byte[] encoding;
final int encLen;
try {
if (cert.aux == null) {
encoding = cert.getEncoded();
encLen = encoding.length;
} else {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
byte[] enc = cert.getEncoded();
baos.write(enc, 0, enc.length);
final X509Aux aux = cert.aux;
ASN1EncodableVector a1 = new ASN1EncodableVector();
if (aux.trust.size() > 0) {
ASN1EncodableVector a2 = new ASN1EncodableVector();
for (String trust : aux.trust) {
a2.add(new ASN1ObjectIdentifier(trust));
}
a1.add(new DLSequence(a2));
}
if (aux.reject.size() > 0) {
ASN1EncodableVector a2 = new ASN1EncodableVector();
for (String reject : aux.reject) {
a2.add(new ASN1ObjectIdentifier(reject));
}
a1.add(new DERTaggedObject(0, new DLSequence(a2)));
}
if (aux.alias != null) {
a1.add(new DERUTF8String(aux.alias));
}
if (aux.keyid != null) {
a1.add(new DEROctetString(aux.keyid));
}
if (aux.other.size() > 0) {
ASN1EncodableVector a2 = new ASN1EncodableVector();
for (ASN1Primitive other : aux.other) a2.add(other);
a1.add(new DERTaggedObject(1, new DLSequence(a2)));
}
enc = new DLSequence(a1).getEncoded();
baos.write(enc, 0, enc.length);
encoding = baos.buffer();
encLen = baos.size();
}
} catch (CertificateEncodingException e) {
throw new IOException("problem with encoding object in write_X509_AUX", e);
}
out.write(BEF_G + PEM_STRING_X509_TRUSTED + AFT);
out.newLine();
writeEncoded(out, encoding, encLen);
out.write(BEF_E + PEM_STRING_X509_TRUSTED + AFT);
out.newLine();
out.flush();
}
use of org.jruby.ext.openssl.util.ByteArrayOutputStream in project jruby-openssl by jruby.
the class PEMInputOutput method writeDSAPrivateKey.
public static void writeDSAPrivateKey(Writer _out, DSAPrivateKey obj, CipherSpec cipher, char[] passwd) throws IOException {
BufferedWriter out = makeBuffered(_out);
PrivateKeyInfo info = new PrivateKeyInfo((ASN1Sequence) new ASN1InputStream(getEncoded(obj)).readObject());
ByteArrayOutputStream bOut = new ByteArrayOutputStream();
ASN1OutputStream aOut = new ASN1OutputStream(bOut);
DSAParameter p = DSAParameter.getInstance(info.getPrivateKeyAlgorithm().getParameters());
ASN1EncodableVector v = new ASN1EncodableVector();
v.add(new ASN1Integer(BigInteger.ZERO));
v.add(new ASN1Integer(p.getP()));
v.add(new ASN1Integer(p.getQ()));
v.add(new ASN1Integer(p.getG()));
BigInteger x = obj.getX();
BigInteger y = p.getG().modPow(x, p.getP());
v.add(new ASN1Integer(y));
v.add(new ASN1Integer(x));
aOut.writeObject(new DLSequence(v));
if (cipher != null && passwd != null) {
writePemEncrypted(out, PEM_STRING_DSA, bOut.buffer(), bOut.size(), cipher, passwd);
} else {
writePemPlain(out, PEM_STRING_DSA, bOut.buffer(), bOut.size());
}
}
Aggregations