public static ECDSASignature decodeFromDER(byte[] bytes) { ASN1InputStream decoder = null; try { decoder = new ASN1InputStream(bytes); DLSequence seq = (DLSequence) decoder.readObject(); if (seq == null) throw new RuntimeException("Reached past end of ASN.1 stream."); ASN1Integer r, s; try { r = (ASN1Integer) seq.getObjectAt(0); s = (ASN1Integer) seq.getObjectAt(1); } catch (ClassCastException e) { throw new IllegalArgumentException(e); } // OpenSSL deviates from the DER spec by interpreting these values as unsigned, though they should not be // Thus, we always use the positive versions. See: http://r6.ca/blog/20111119T211504Z.html return new ECDSASignature(r.getPositiveValue(), s.getPositiveValue()); } catch (IOException e) { throw new RuntimeException(e); } finally { if (decoder != null) try { decoder.close(); } catch (IOException x) {} } }
private Object readObject() { try { return aIn.readObject(); } catch (IOException e) { throw new ASN1ParsingException("malformed DER construction: " + e, e); } } }
private Object readObject() { try { return aIn.readObject(); } catch (IOException e) { throw new ASN1ParsingException("malformed DER construction: " + e, e); } } }
private static ASN1Sequence readSequence( ASN1InputStream aIn) throws IOException { try { return ASN1Sequence.getInstance(aIn.readObject()); } catch (IllegalArgumentException e) { throw new IOException("not an ASN.1 Sequence: " + e); } }
private static ASN1Sequence readSequence( ASN1InputStream aIn) throws IOException { try { return ASN1Sequence.getInstance(aIn.readObject()); } catch (IllegalArgumentException e) { throw new IOException("not an ASN.1 Sequence: " + e); } }
private static ASN1Sequence getReq( byte[] r) throws IOException { ASN1InputStream aIn = new ASN1InputStream(new ByteArrayInputStream(r)); return ASN1Sequence.getInstance(aIn.readObject()); }
private static ASN1Sequence getReq( byte[] r) throws IOException { ASN1InputStream aIn = new ASN1InputStream(new ByteArrayInputStream(r)); return ASN1Sequence.getInstance(aIn.readObject()); }
public static void main( String args[]) throws Exception { FileInputStream fIn = new FileInputStream(args[0]); ASN1InputStream bIn = new ASN1InputStream(fIn); Object obj = null; while ((obj = bIn.readObject()) != null) { System.out.println(ASN1Dump.dumpAsString(obj)); } } }
public static void main( String args[]) throws Exception { FileInputStream fIn = new FileInputStream(args[0]); ASN1InputStream bIn = new ASN1InputStream(fIn); Object obj = null; while ((obj = bIn.readObject()) != null) { System.out.println(ASN1Dump.dumpAsString(obj)); } } }
public void setPublicKey( PublicKey key) { try { tbsGen.setSubjectPublicKeyInfo(new SubjectPublicKeyInfo((ASN1Sequence)new ASN1InputStream( new ByteArrayInputStream(key.getEncoded())).readObject())); } catch (Exception e) { throw new IllegalArgumentException("unable to process key - " + e.toString()); } }
ASN1EncodableVector buildEncodableVector() throws IOException { ASN1EncodableVector v = new ASN1EncodableVector(); ASN1Primitive o; while ((o = readObject()) != null) { v.add(o); } return v; }
private CRL readDERCRL( ASN1InputStream aIn) throws IOException, CRLException { return getCRL(ASN1Sequence.getInstance(aIn.readObject())); }
private java.security.cert.Certificate readDERCertificate( ASN1InputStream dIn) throws IOException, CertificateParsingException { return getCertificate(ASN1Sequence.getInstance(dIn.readObject())); }
/** * Return the enclosed object assuming explicit tagging. * * @return the resulting object * @throws IOException if reconstruction fails. */ public ASN1Primitive getObject() throws IOException { return new ASN1InputStream(getContents()).readObject(); }
public X509TrustedCertificateBlock(byte[] encoding) throws IOException { ASN1InputStream aIn = new ASN1InputStream(encoding); this.certificateHolder = new X509CertificateHolder(aIn.readObject().getEncoded()); this.trustBlock = new CertificateTrustBlock(aIn.readObject().getEncoded()); }
public X509TrustedCertificateBlock(byte[] encoding) throws IOException { ASN1InputStream aIn = new ASN1InputStream(encoding); this.certificateHolder = new X509CertificateHolder(aIn.readObject().getEncoded()); this.trustBlock = new CertificateTrustBlock(aIn.readObject().getEncoded()); }
private X509CertificatePair readDERCrossCertificatePair( InputStream in) throws IOException, CertificateParsingException { ASN1InputStream dIn = new ASN1InputStream(in); ASN1Sequence seq = (ASN1Sequence)dIn.readObject(); CertificatePair pair = CertificatePair.getInstance(seq); return new X509CertificatePair(pair); }
/** * Create a private key parameter from a PKCS8 PrivateKeyInfo encoding read from a * stream. * * @param inStr the stream to read the PrivateKeyInfo encoding from * @return a suitable private key parameter * @throws IOException on an error decoding the key */ public static AsymmetricKeyParameter createKey(InputStream inStr) throws IOException { return createKey(PrivateKeyInfo.getInstance(new ASN1InputStream(inStr).readObject())); }
/** * Create a public key from a SubjectPublicKeyInfo encoding read from a stream * * @param inStr the stream to read the SubjectPublicKeyInfo encoding from * @return the appropriate key parameter * @throws IOException on an error decoding the key */ public static AsymmetricKeyParameter createKey(InputStream inStr) throws IOException { return createKey(SubjectPublicKeyInfo.getInstance(new ASN1InputStream(inStr).readObject())); }
void fromByteArray(final byte[] encodedData) throws SecureMessagingException { try ( final ASN1InputStream asn1in = new ASN1InputStream(encodedData); ) { this.to = (DERTaggedObject)asn1in.readObject(); } catch (final IOException e) { throw new SecureMessagingException(e); } final DEROctetString ocs = (DEROctetString) this.to.getObject(); this.data = ocs.getOctets(); }