List of usage examples for org.bouncycastle.asn1 ASN1Integer ASN1Integer
public ASN1Integer(byte[] bytes)
From source file:org.xwiki.crypto.pkix.internal.BcX509v1TBSCertificateBuilder.java
License:Open Source License
@Override public BcX509TBSCertificateBuilder setSerialNumber(BigInteger serial) { this.tbsGen.setSerialNumber(new ASN1Integer(serial)); return this; }
From source file:org.xwiki.crypto.signer.internal.factory.BcRsaSsaPssSignerFactory.java
License:Open Source License
@Override protected AlgorithmIdentifier getSignerAlgorithmIdentifier(AsymmetricCipherParameters parameters) { if (parameters instanceof AsymmetricKeyParameters) { AlgorithmIdentifier sha1AlgId = new AlgorithmIdentifier(X509ObjectIdentifiers.id_SHA1); return new AlgorithmIdentifier(PKCSObjectIdentifiers.id_RSASSA_PSS, DERNull.INSTANCE); } else if (parameters instanceof PssSignerParameters) { PssParameters pssParams = ((PssSignerParameters) parameters).getPssParameters(); BcDigestFactory factory = getDigestFactory(pssParams.getHashAlgorithm()); return new AlgorithmIdentifier(PKCSObjectIdentifiers.id_RSASSA_PSS, new RSASSAPSSparams( factory.getAlgorithmIdentifier(), new AlgorithmIdentifier(PKCSObjectIdentifiers.id_mgf1, getDigestFactory(pssParams.getMaskGenAlgorithm()).getAlgorithmIdentifier()), new ASN1Integer( pssParams.getSaltLength() >= 0 ? pssParams.getSaltLength() : factory.getDigestSize()), new ASN1Integer(pssParams.getTrailerField()))); }//from w w w.java2 s. c o m throw new UnsupportedOperationException(PSS_PARAMS_ERROR + parameters.getClass().getName()); }
From source file:support.revocation.OCSP.java
License:Apache License
/** * @return an OCSP request for the given certificate that was issued by * the issuer which the given issuer certificate is issued for * @param certificate/*from ww w. ja v a 2s . c om*/ * @param issuerCertificate * @throws IOException * @throws GeneralSecurityException */ private static OCSPRequest generateOCSPRequest(X509Certificate certificate, X509Certificate issuerCertificate) throws IOException, GeneralSecurityException { MessageDigest digest = MessageDigest.getInstance("SHA1"); AlgorithmIdentifier digestAlgorithm = new AlgorithmIdentifier( new ASN1ObjectIdentifier(OIWObjectIdentifiers.idSHA1.getId())); if (!issuerCertificate.getSubjectX500Principal().equals(certificate.getIssuerX500Principal())) throw new CertificateException("Issuing cerrtificate and issued certificate mismatch"); // issuer hash digest.update(issuerCertificate.getSubjectX500Principal().getEncoded()); ASN1OctetString issuerNameHash = new DEROctetString(digest.digest()); // issuer public key hash SubjectPublicKeyInfo publicKey = SubjectPublicKeyInfo .getInstance(parseASN1(issuerCertificate.getPublicKey().getEncoded())); digest.update(publicKey.getPublicKeyData().getBytes()); ASN1OctetString issuerKeyHash = new DEROctetString(digest.digest()); // certificate serial number ASN1Integer serialNumber = new ASN1Integer(certificate.getSerialNumber()); // OCSP request CertID certID = new CertID(digestAlgorithm, issuerNameHash, issuerKeyHash, serialNumber); ASN1Sequence requestList = new DERSequence(new Request(certID, null)); TBSRequest request = new TBSRequest(null, requestList, (Extensions) null); return new OCSPRequest(request, null); }
From source file:tests.asn1.AccuracyTest.java
License:Apache License
/** * Produces input stream containing ASN.1 representation of accuracy. *//* w w w . j a v a2 s .c om*/ private InputStream getDerStream(Integer seconds, DERTaggedObject millis, DERTaggedObject micros) throws IOException { ASN1EncodableVector v = new ASN1EncodableVector(); if (seconds != null) { v.add(new ASN1Integer(seconds.intValue())); } if (millis != null) { v.add(millis); } if (micros != null) { v.add(micros); } byte[] der = new DERSequence(v).getEncoded(ASN1Encoding.DER); return new ByteArrayInputStream(der); }
From source file:tests.asn1.AccuracyTest.java
License:Apache License
/** * Produces ASN.1 tagged object./* ww w .j a va2 s. co m*/ */ private DERTaggedObject getDerTagged(boolean isExplicit, int tagNumber, int value) throws IOException { ASN1Integer asnValue = new ASN1Integer(value); return new DERTaggedObject(isExplicit, tagNumber, asnValue); }
From source file:tests.asn1.CertTokenTest.java
License:Apache License
/** * Produces input stream containing ASN.1 representation of signature info. *///from w w w. j a v a2 s .co m private InputStream getDerStream(Integer version, byte[] history, byte[] publishedData, byte[][] pubReferences) throws IOException { ASN1EncodableVector v = new ASN1EncodableVector(); if (version != null) { v.add(new ASN1Integer(version.intValue())); } if (history != null) { v.add(new DEROctetString(history)); } if (publishedData != null) { v.add(new ASN1InputStream(publishedData).readObject()); } if (pubReferences != null) { DEROctetString[] derRefs = new DEROctetString[pubReferences.length]; for (int i = 0; i < pubReferences.length; i++) { derRefs[i] = new DEROctetString(pubReferences[i]); } v.add(new DERSet(derRefs)); } // Extensions skipped -- see CertToken code for comments byte[] der = new DERSequence(v).getEncoded(ASN1Encoding.DER); return new ByteArrayInputStream(der); }
From source file:tests.asn1.PublishedDataTest.java
License:Apache License
/** * Produces input stream containing ASN.1 representation of published data. *//*from w ww . j a v a 2 s . c o m*/ private InputStream getDerStream(BigInteger publicationId, byte[] publicationImprint) throws IOException { ASN1EncodableVector v = new ASN1EncodableVector(); if (publicationId != null) { v.add(new ASN1Integer(publicationId)); } if (publicationImprint != null) { v.add(new DEROctetString(publicationImprint)); } byte[] der = new DERSequence(v).getEncoded(ASN1Encoding.DER); return new ByteArrayInputStream(der); }
From source file:tests.asn1.SignedDataTest.java
License:Apache License
/** * Produces input stream containing ASN.1 representation of signed data. *//*w w w .j a v a 2s . c o m*/ private InputStream getDerStream(Integer version, String[] digestAlgorithms, DERSequence eContent, DERTaggedObject certificates, byte[][] signerInfos) throws IOException { ASN1EncodableVector v = new ASN1EncodableVector(); if (version != null) { v.add(new ASN1Integer(version.intValue())); } if (digestAlgorithms != null) { AlgorithmIdentifier[] derAlgs = new AlgorithmIdentifier[digestAlgorithms.length]; for (int i = 0; i < digestAlgorithms.length; i++) { derAlgs[i] = new AlgorithmIdentifier(new ASN1ObjectIdentifier(digestAlgorithms[i])); } v.add(new DERSet(derAlgs)); } if (eContent != null) { v.add(eContent); } if (certificates != null) { v.add(certificates); } // CRLs ignored if (signerInfos != null) { ASN1Encodable[] derInfos = new ASN1Encodable[signerInfos.length]; for (int i = 0; i < signerInfos.length; i++) { derInfos[i] = new ASN1InputStream(signerInfos[i]).readObject(); } v.add(new DERSet(derInfos)); } byte[] der = new DERSequence(v).getEncoded(ASN1Encoding.DER); return new ByteArrayInputStream(der); }
From source file:tests.asn1.SignerInfoTest.java
License:Apache License
/** * Produces input stream containing ASN.1 representation of signer info. *///from w w w. ja va 2 s . com private InputStream getDerStream(Integer version, byte[] signerId, String digestAlgorithm, DERTaggedObject signedAttrs, String signatureAlgorithm, byte[] signature, DERTaggedObject unsignedAttrs) throws IOException { ASN1EncodableVector v = new ASN1EncodableVector(); if (version != null) { v.add(new ASN1Integer(version.intValue())); } if (signerId != null) { v.add(new ASN1InputStream(signerId).readObject()); } if (digestAlgorithm != null) { v.add(new AlgorithmIdentifier(new ASN1ObjectIdentifier(digestAlgorithm))); } if (signedAttrs != null) { v.add(signedAttrs); } if (signatureAlgorithm != null) { v.add(new AlgorithmIdentifier(new ASN1ObjectIdentifier(signatureAlgorithm))); } if (signature != null) { v.add(new DEROctetString(signature)); } if (unsignedAttrs != null) { v.add(unsignedAttrs); } byte[] der = new DERSequence(v).getEncoded(ASN1Encoding.DER); return new ByteArrayInputStream(der); }
From source file:tests.asn1.TstInfoTest.java
License:Apache License
/** * Produces input stream containing ASN.1 representation of TST info. *///from w ww . j a v a2 s .co m private InputStream getDerStream(Integer version, String policy, byte[] messageImprint, BigInteger serialNumber, String genTime, byte[] accuracy, Boolean ordering, BigInteger nonce, DERTaggedObject tsa) throws IOException { ASN1EncodableVector v = new ASN1EncodableVector(); if (version != null) { v.add(new ASN1Integer(version.intValue())); } if (policy != null) { v.add(new ASN1ObjectIdentifier(policy)); } if (messageImprint != null) { v.add(new ASN1InputStream(messageImprint).readObject()); } if (serialNumber != null) { v.add(new ASN1Integer(serialNumber)); } if (genTime != null) { v.add(new ASN1GeneralizedTime(genTime)); } if (accuracy != null) { v.add(new ASN1InputStream(accuracy).readObject()); } if (ordering != null) { v.add(new ASN1Boolean(ordering.booleanValue())); } if (nonce != null) { v.add(new ASN1Integer(nonce.intValue())); } if (tsa != null) { v.add(tsa); } // Extensions skipped -- see TstInfo code for comments byte[] der = new DERSequence(v).getEncoded(ASN1Encoding.DER); return new ByteArrayInputStream(der); }