List of usage examples for org.bouncycastle.asn1 ASN1EncodableVector add
public void add(ASN1Encodable element)
From source file:net.sf.keystore_explorer.crypto.csr.spkac.Spkac.java
License:Open Source License
private byte[] encodeRsaPublicKeyAsBitString(RSAPublicKey rsaPublicKey) throws SpkacException { try {//w w w .j a va 2s . c om ASN1EncodableVector vec = new ASN1EncodableVector(); vec.add(new ASN1Integer(rsaPublicKey.getModulus())); vec.add(new ASN1Integer(rsaPublicKey.getPublicExponent())); DERSequence derSequence = new DERSequence(vec); return derSequence.getEncoded(ASN1Encoding.DER); } catch (Exception ex) { throw new SpkacException(res.getString("NoEncodeRsaPublicKey.exception.message"), ex); } }
From source file:net.sf.keystore_explorer.crypto.csr.spkac.Spkac.java
License:Open Source License
private ASN1Sequence createSignedPublicKeyAndChallenge() throws SpkacException { ASN1EncodableVector vec = new ASN1EncodableVector(); vec.add(new ASN1ObjectIdentifier(getSignatureAlgorithm().oid())); vec.add(DERNull.INSTANCE);//w ww . j av a 2 s . com DERSequence signatureAlgorithm = new DERSequence(vec); vec = new ASN1EncodableVector(); vec.add(createPublicKeyAndChallenge()); vec.add(signatureAlgorithm); vec.add(new DERBitString(signature)); return new DERSequence(vec); }
From source file:net.sf.keystore_explorer.crypto.csr.spkac.Spkac.java
License:Open Source License
private ASN1Sequence createPublicKeyAndChallenge() throws SpkacException { ASN1EncodableVector publicKeyAlgorithm = new ASN1EncodableVector(); publicKeyAlgorithm.add(new ASN1ObjectIdentifier(getPublicKeyAlg().oid())); if (getPublicKey() instanceof RSAPublicKey) { publicKeyAlgorithm.add(DERNull.INSTANCE); } else {//from w w w . ja v a2 s.c om DSAParams dsaParams = ((DSAPublicKey) getPublicKey()).getParams(); ASN1EncodableVector dssParams = new ASN1EncodableVector(); dssParams.add(new ASN1Integer(dsaParams.getP())); dssParams.add(new ASN1Integer(dsaParams.getQ())); dssParams.add(new ASN1Integer(dsaParams.getG())); publicKeyAlgorithm.add(new DERSequence(dssParams)); } ASN1EncodableVector spki = new ASN1EncodableVector(); spki.add(new DERSequence(publicKeyAlgorithm)); spki.add(encodePublicKeyAsBitString(getPublicKey())); ASN1EncodableVector publicKeyAndChallenge = new ASN1EncodableVector(); publicKeyAndChallenge.add(new DERSequence(spki)); publicKeyAndChallenge.add(new DERIA5String(getChallenge())); return new DERSequence(publicKeyAndChallenge); }
From source file:net.sf.keystore_explorer.crypto.privatekey.OpenSslPvkUtil.java
License:Open Source License
/** * OpenSSL encode a private key./*from w ww . j a va 2s . c o m*/ * * @return The encoding * @param privateKey * The private key * @throws CryptoException * Problem encountered while getting the encoded private key */ public static byte[] get(PrivateKey privateKey) throws CryptoException { // DER encoding for each key type is a sequence ASN1EncodableVector vec = new ASN1EncodableVector(); if (privateKey instanceof RSAPrivateCrtKey) { RSAPrivateCrtKey rsaPrivateKey = (RSAPrivateCrtKey) privateKey; vec.add(new ASN1Integer(VERSION)); vec.add(new ASN1Integer(rsaPrivateKey.getModulus())); vec.add(new ASN1Integer(rsaPrivateKey.getPublicExponent())); vec.add(new ASN1Integer(rsaPrivateKey.getPrivateExponent())); vec.add(new ASN1Integer(rsaPrivateKey.getPrimeP())); vec.add(new ASN1Integer(rsaPrivateKey.getPrimeQ())); vec.add(new ASN1Integer(rsaPrivateKey.getPrimeExponentP())); vec.add(new ASN1Integer(rsaPrivateKey.getPrimeExponentQ())); vec.add(new ASN1Integer(rsaPrivateKey.getCrtCoefficient())); } else { DSAPrivateKey dsaPrivateKey = (DSAPrivateKey) privateKey; DSAParams dsaParams = dsaPrivateKey.getParams(); BigInteger primeModulusP = dsaParams.getP(); BigInteger primeQ = dsaParams.getQ(); BigInteger generatorG = dsaParams.getG(); BigInteger secretExponentX = dsaPrivateKey.getX(); // Derive public key from private key parts, ie Y = G^X mod P BigInteger publicExponentY = generatorG.modPow(secretExponentX, primeModulusP); vec.add(new ASN1Integer(VERSION)); vec.add(new ASN1Integer(primeModulusP)); vec.add(new ASN1Integer(primeQ)); vec.add(new ASN1Integer(generatorG)); vec.add(new ASN1Integer(publicExponentY)); vec.add(new ASN1Integer(secretExponentX)); } DERSequence derSequence = new DERSequence(vec); try { return derSequence.getEncoded(); } catch (IOException ex) { throw new CryptoException(res.getString("NoDerEncodeOpenSslPrivateKey.exception.message"), ex); } }
From source file:net.sf.keystore_explorer.crypto.publickey.KeyIdentifierGenerator.java
License:Open Source License
private byte[] encodeRsaPublicKeyAsBitString(RSAPublicKey rsaPublicKey) throws IOException { ASN1EncodableVector vec = new ASN1EncodableVector(); vec.add(new ASN1Integer(rsaPublicKey.getModulus())); vec.add(new ASN1Integer(rsaPublicKey.getPublicExponent())); DERSequence derSequence = new DERSequence(vec); return derSequence.getEncoded(); }
From source file:net.sf.keystore_explorer.crypto.signing.JarSigner.java
License:Open Source License
private static CMSSignedData addTimestamp(String tsaUrl, CMSSignedData signedData) throws IOException { Collection<SignerInformation> signerInfos = signedData.getSignerInfos().getSigners(); // get signature of first signer (should be the only one) SignerInformation si = signerInfos.iterator().next(); byte[] signature = si.getSignature(); // send request to TSA byte[] token = TimeStampingClient.getTimeStampToken(tsaUrl, signature, DigestType.SHA1); // create new SignerInformation with TS attribute Attribute tokenAttr = new Attribute(PKCSObjectIdentifiers.id_aa_signatureTimeStampToken, new DERSet(ASN1Primitive.fromByteArray(token))); ASN1EncodableVector timestampVector = new ASN1EncodableVector(); timestampVector.add(tokenAttr); AttributeTable at = new AttributeTable(timestampVector); si = SignerInformation.replaceUnsignedAttributes(si, at); signerInfos.clear();//from www. j a v a2 s . c o m signerInfos.add(si); SignerInformationStore newSignerStore = new SignerInformationStore(signerInfos); // create new signed data CMSSignedData newSignedData = CMSSignedData.replaceSigners(signedData, newSignerStore); return newSignedData; }
From source file:net.sf.keystore_explorer.crypto.x509.CRLDistributionPoints.java
License:Open Source License
@Override public ASN1Primitive toASN1Primitive() { ASN1EncodableVector v = new ASN1EncodableVector(); Iterator<DistributionPoint> it = distributionPointList.iterator(); while (it.hasNext()) { v.add(it.next().toASN1Primitive()); }//from w w w . j ava 2 s . co m return new DERSequence(v); }
From source file:net.sf.keystore_explorer.crypto.x509.GeneralSubtrees.java
License:Open Source License
@Override public ASN1Primitive toASN1Primitive() { ASN1EncodableVector vec = new ASN1EncodableVector(); for (int i = 0; i < subtrees.size(); i++) { vec.add(subtrees.get(i)); }//from w w w. j a v a 2 s. c o m return new DERSequence(vec); }
From source file:net.sf.keystore_explorer.crypto.x509.PolicyConstraints.java
License:Open Source License
@Override public ASN1Primitive toASN1Primitive() { ASN1EncodableVector vec = new ASN1EncodableVector(); if (requireExplicitPolicy != -1) { vec.add(new DERTaggedObject(0, new ASN1Integer(requireExplicitPolicy))); }/*from ww w . jav a 2s .c o m*/ if (inhibitPolicyMapping != -1) { vec.add(new DERTaggedObject(1, new ASN1Integer(inhibitPolicyMapping))); } return new DERSequence(vec); }
From source file:net.sf.keystore_explorer.crypto.x509.PolicyMapping.java
License:Open Source License
@Override public ASN1Primitive toASN1Primitive() { ASN1EncodableVector dv = new ASN1EncodableVector(); dv.add(issuerDomainPolicy); dv.add(subjectDomainPolicy);/*from w w w. j a v a2s. c o m*/ return new DERSequence(dv); }