List of usage examples for org.bouncycastle.asn1 ASN1InputStream ASN1InputStream
public ASN1InputStream(byte[] input)
From source file:com.guardtime.asn1.TimeSignature.java
License:Apache License
/** * Parses a DER-encoded {@code TimeSignature} out from the given input stream. * * @param in/*from w w w . j a va 2 s .c o m*/ * the input stream to read data from. * @return the {@code TimeSignature} object. * @throws Asn1FormatException * if the data read from {@code in} does not represent a valid * {@code TimeSignature} object. * @throws IOException * if {@code in} throws one. */ public static TimeSignature getInstance(InputStream in) throws Asn1FormatException, IOException { if (in == null) { throw new IllegalArgumentException("invalid input stream: null"); } try { ASN1Object obj = new ASN1InputStream(in).readObject(); return new TimeSignature(obj); } catch (IOException e) { if (isAsnParserException(e)) { throw new Asn1FormatException("time signature has invalid format", e); } else { throw e; } } catch (IllegalArgumentException e) { if (isAsnParserException(e)) { throw new Asn1FormatException("time signature has invalid format", e); } else { throw e; } } }
From source file:com.guardtime.asn1.TimestampResponse.java
License:Apache License
/** * Parses a DER-encoded {@code TimeStampResp} out from the given input * stream.//from w ww. j av a 2 s .c o m * * @param in * the input stream to read data from. * @return the {@code TimeStampResp} object. * @throws Asn1FormatException * if the data read from {@code in} does not represent a valid * {@code TimeStampResp} object. * @throws IOException * if {@code in} throws one. */ public static TimestampResponse getInstance(InputStream in) throws Asn1FormatException, IOException { if (in == null) { throw new IllegalArgumentException("invalid input stream: null"); } try { ASN1Object obj = new ASN1InputStream(in).readObject(); return new TimestampResponse(obj); } catch (IOException e) { if (isAsnParserException(e)) { throw new Asn1FormatException("timestamp response has invalid format", e); } else { throw e; } } catch (IllegalArgumentException e) { if (isAsnParserException(e)) { throw new Asn1FormatException("timestamp response has invalid format", e); } else { throw e; } } }
From source file:com.guardtime.asn1.TstInfo.java
License:Apache License
/** * Parses a DER-encoded {@code TSTInfo} out from the given input stream. * * @param in//from ww w . j av a 2 s .c o m * the input stream to read data from. * @return the {@code TSTInfo} object. * @throws Asn1FormatException * if the data read from {@code in} does not represent a valid * {@code TSTInfo} object. * @throws IOException * if {@code in} throws one. */ public static TstInfo getInstance(InputStream in) throws Asn1FormatException, IOException { if (in == null) { throw new IllegalArgumentException("invalid input stream: null"); } try { ASN1Object obj = new ASN1InputStream(in).readObject(); return new TstInfo(obj); } catch (IOException e) { if (isAsnParserException(e)) { throw new Asn1FormatException("TST info has invalid format", e); } else { throw e; } } catch (IllegalArgumentException e) { if (isAsnParserException(e)) { throw new Asn1FormatException("TST info has invalid format", e); } else { throw e; } } }
From source file:com.hierynomus.spnego.NegTokenInit.java
License:Apache License
private NegTokenInit read(Buffer<?> buffer) throws SpnegoException { try (ASN1InputStream is = new ASN1InputStream(buffer.asInputStream())) { ASN1Primitive applicationSpecific = is.readObject(); if (!(applicationSpecific instanceof BERApplicationSpecific || applicationSpecific instanceof DERApplicationSpecific)) { throw new SpnegoException( "Incorrect GSS-API ASN.1 token received, expected to find an [APPLICATION 0], not: " + applicationSpecific); }// www . ja v a2 s .com ASN1Sequence implicitSequence = (ASN1Sequence) ((ASN1ApplicationSpecific) applicationSpecific) .getObject(BERTags.SEQUENCE); ASN1Encodable spnegoOid = implicitSequence.getObjectAt(0); if (!(spnegoOid instanceof ASN1ObjectIdentifier)) { throw new SpnegoException("Expected to find the SPNEGO OID (" + SPNEGO + "), not: " + spnegoOid); } parseSpnegoToken(implicitSequence.getObjectAt(1)); } catch (IOException ioe) { throw new SpnegoException("Could not read NegTokenInit from buffer", ioe); } return this; }
From source file:com.hierynomus.spnego.NegTokenTarg.java
License:Apache License
private NegTokenTarg read(Buffer<?> buffer) throws SpnegoException { try (ASN1InputStream is = new ASN1InputStream(buffer.asInputStream())) { ASN1Primitive instance = is.readObject(); parseSpnegoToken(instance);//from w w w.ja v a 2 s .co m } catch (IOException e) { throw new SpnegoException("Could not read NegTokenTarg from buffer", e); } return this; }
From source file:com.igeekinc.indelible.indeliblefs.security.EntityAuthenticationClient.java
License:Open Source License
public static DataMoverSessionID getSessionIDFromCertificate(X509Certificate checkCert) throws IOException { byte[] checkSessionIDBytesEncoded = checkCert .getExtensionValue(X509Extensions.SubjectAlternativeName.toString()); ASN1InputStream decoder = new ASN1InputStream(new ByteArrayInputStream(checkSessionIDBytesEncoded)); DERObject checkObject = decoder.readObject(); DEROctetString checkOctetString = (DEROctetString) checkObject; byte[] checkSessionIDBytes = checkOctetString.getOctets(); DataMoverSessionID checkSessionID = (DataMoverSessionID) ObjectIDFactory .reconstituteFromBytes(checkSessionIDBytes); return checkSessionID; }
From source file:com.infinities.keystone4j.ssl.CRLVerifier.java
License:Apache License
/** * Extracts all CRL distribution point URLs from the * "CRL Distribution Point" extension in a X.509 certificate. If CRL * distribution point extension is unavailable, returns an empty list. *///from www. j a v a 2s. c om public static List<String> getCrlDistributionPoints(X509Certificate cert) throws CertificateParsingException, IOException { byte[] crldpExt = cert.getExtensionValue(X509Extension.cRLDistributionPoints.getId()); if (crldpExt == null) { return new ArrayList<String>(); } ASN1InputStream oAsnInStream = null; ASN1InputStream oAsnInStream2 = null; try { oAsnInStream = new ASN1InputStream(new ByteArrayInputStream(crldpExt)); DERObject derObjCrlDP = oAsnInStream.readObject(); DEROctetString dosCrlDP = (DEROctetString) derObjCrlDP; byte[] crldpExtOctets = dosCrlDP.getOctets(); oAsnInStream2 = new ASN1InputStream(new ByteArrayInputStream(crldpExtOctets)); DERObject derObj2 = oAsnInStream2.readObject(); CRLDistPoint distPoint = CRLDistPoint.getInstance(derObj2); List<String> crlUrls = new ArrayList<String>(); for (DistributionPoint dp : distPoint.getDistributionPoints()) { DistributionPointName dpn = dp.getDistributionPoint(); // Look for URIs in fullName if (dpn != null && dpn.getType() == DistributionPointName.FULL_NAME) { GeneralName[] genNames = GeneralNames.getInstance(dpn.getName()).getNames(); // Look for an URI for (int j = 0; j < genNames.length; j++) { if (genNames[j].getTagNo() == GeneralName.uniformResourceIdentifier) { String url = DERIA5String.getInstance(genNames[j].getName()).getString(); crlUrls.add(url); } } } } return crlUrls; } finally { if (oAsnInStream != null) { oAsnInStream.close(); } if (oAsnInStream2 != null) { oAsnInStream2.close(); } } }
From source file:com.itextpdf.kernel.crypto.securityhandler.EncryptionUtils.java
License:Open Source License
static DERForRecipientParams calculateDERForRecipientParams(byte[] in) throws IOException, GeneralSecurityException { String s = "1.2.840.113549.3.2"; DERForRecipientParams parameters = new DERForRecipientParams(); AlgorithmParameterGenerator algorithmparametergenerator = AlgorithmParameterGenerator.getInstance(s); AlgorithmParameters algorithmparameters = algorithmparametergenerator.generateParameters(); ByteArrayInputStream bytearrayinputstream = new ByteArrayInputStream( algorithmparameters.getEncoded("ASN.1")); ASN1InputStream asn1inputstream = new ASN1InputStream(bytearrayinputstream); ASN1Primitive derobject = asn1inputstream.readObject(); KeyGenerator keygenerator = KeyGenerator.getInstance(s); keygenerator.init(128);//from w w w .jav a 2 s.c o m SecretKey secretkey = keygenerator.generateKey(); Cipher cipher = Cipher.getInstance(s); cipher.init(1, secretkey, algorithmparameters); parameters.abyte0 = secretkey.getEncoded(); parameters.abyte1 = cipher.doFinal(in); parameters.algorithmIdentifier = new AlgorithmIdentifier(new ASN1ObjectIdentifier(s), derobject); return parameters; }
From source file:com.itextpdf.kernel.crypto.securityhandler.PubKeySecurityHandler.java
License:Open Source License
private KeyTransRecipientInfo computeRecipientInfo(X509Certificate x509certificate, byte[] abyte0) throws GeneralSecurityException, IOException { ASN1InputStream asn1inputstream = new ASN1InputStream( new ByteArrayInputStream(x509certificate.getTBSCertificate())); TBSCertificateStructure tbscertificatestructure = TBSCertificateStructure .getInstance(asn1inputstream.readObject()); assert tbscertificatestructure != null; AlgorithmIdentifier algorithmidentifier = tbscertificatestructure.getSubjectPublicKeyInfo().getAlgorithm(); IssuerAndSerialNumber issuerandserialnumber = new IssuerAndSerialNumber(tbscertificatestructure.getIssuer(), tbscertificatestructure.getSerialNumber().getValue()); byte[] cipheredBytes = EncryptionUtils.cipherBytes(x509certificate, abyte0, algorithmidentifier); DEROctetString deroctetstring = new DEROctetString(cipheredBytes); RecipientIdentifier recipId = new RecipientIdentifier(issuerandserialnumber); return new KeyTransRecipientInfo(recipId, algorithmidentifier, deroctetstring); }
From source file:com.itextpdf.signatures.CertificateInfo.java
License:Open Source License
/** * Get the "issuer" from the TBSCertificate bytes that are passed in. * * @param enc a TBSCertificate in a byte array * @return an ASN1Primitive/*from w w w .ja v a 2 s .com*/ */ public static ASN1Primitive getIssuer(byte[] enc) { try { ASN1InputStream in = new ASN1InputStream(new ByteArrayInputStream(enc)); ASN1Sequence seq = (ASN1Sequence) in.readObject(); return (ASN1Primitive) seq.getObjectAt(seq.getObjectAt(0) instanceof ASN1TaggedObject ? 3 : 2); } catch (IOException e) { throw new PdfException(e); } }