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) {} } }
ASN1EncodableVector buildDEREncodableVector( DefiniteLengthInputStream dIn) throws IOException { return new ASN1InputStream(dIn).buildEncodableVector(); }
private static ASN1Sequence toDERSequence( byte[] bytes) { try { ASN1InputStream dIn = new ASN1InputStream(bytes); return (ASN1Sequence)dIn.readObject(); } catch (Exception e) { throw new IllegalArgumentException("badly encoded request"); } }
/** * @deprecated use classes in org.spongycastle.cert.ocsp. */ public OCSPResp( byte[] resp) throws IOException { this(new ASN1InputStream(resp)); }
private Object readObject() { try { return aIn.readObject(); } catch (IOException e) { throw new ASN1ParsingException("malformed DER construction: " + e, e); } } }
private static ASN1Sequence toDERSequence( byte[] bytes) { try { ASN1InputStream dIn = new ASN1InputStream(bytes); return (ASN1Sequence)dIn.readObject(); } catch (Exception e) { throw new IllegalArgumentException("badly encoded request"); } }
/** * @deprecated use classes in org.spongycastle.cert.ocsp. */ public OCSPResp( InputStream in) throws IOException { this(new ASN1InputStream(in)); }
private Object readObject() { try { return aIn.readObject(); } catch (IOException e) { throw new ASN1ParsingException("malformed DER construction: " + e, e); } } }
ASN1EncodableVector buildDEREncodableVector( DefiniteLengthInputStream dIn) throws IOException { return new ASN1InputStream(dIn).buildEncodableVector(); }
void fromByteArray(final byte[] encodedData) throws SecureMessagingException { try ( final ASN1InputStream asn1in = new ASN1InputStream(encodedData); ) { this.to = (DERTaggedObject) asn1in.readObject(); asn1in.close(); } catch (final IOException e) { throw new SecureMessagingException(e); } final DEROctetString ocs = (DEROctetString) this.to.getObject(); this.data = ocs.getOctets(); }
/** * 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 OCSPReq( byte[] req) throws IOException { this(new ASN1InputStream(req)); }
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); } }
public static ECDSASignature decodeFromDER(byte[] bytes) { try { ASN1InputStream decoder = new ASN1InputStream(bytes); DLSequence seq = (DLSequence) decoder.readObject(); DERInteger r, s; try { r = (DERInteger) seq.getObjectAt(0); s = (DERInteger) seq.getObjectAt(1); } catch (ClassCastException e) { throw new IllegalArgumentException(e); } decoder.close(); // 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); } }
private static Enumeration<?> getCAdESObjects(final byte[] data) throws IOException { try ( final ASN1InputStream is = new ASN1InputStream(data); ) { final ASN1Sequence dsq = (ASN1Sequence) is.readObject(); return dsq.getObjects(); } }
public OCSPReq( byte[] req) throws IOException { this(new ASN1InputStream(req)); }
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); } }
final ASN1InputStream is = new ASN1InputStream(data); ) { final ASN1Sequence dsq = (ASN1Sequence) is.readObject(); is.close(); final Enumeration<?> e = dsq.getObjects();
/** * for when the public key is an encoded object - if the bitstring * can't be decoded this routine throws an IOException. * * @exception IOException - if the bit string doesn't represent a DER * encoded object. * @return the public key as an ASN.1 primitive. */ public ASN1Primitive parsePublicKey() throws IOException { ASN1InputStream aIn = new ASN1InputStream(keyData.getOctets()); return aIn.readObject(); }
public OCSPReq( InputStream in) throws IOException { this(new ASN1InputStream(in)); }