List of usage examples for org.bouncycastle.asn1 ASN1EncodableVector ASN1EncodableVector
public ASN1EncodableVector()
From source file:net.jsign.asn1.authenticode.SpcSerializedObject.java
License:Apache License
@Override public ASN1Primitive toASN1Primitive() { ASN1EncodableVector v = new ASN1EncodableVector(); v.add(classId);//from w ww .j ava 2s. c o m v.add(serializedData); return new DERSequence(v); }
From source file:net.jsign.asn1.authenticode.SpcSpOpusInfo.java
License:Apache License
@Override public ASN1Primitive toASN1Primitive() { ASN1EncodableVector v = new ASN1EncodableVector(); if (programName != null) { v.add(new DERTaggedObject(true, 0, programName)); }//from w w w . ja va 2s .c om if (moreInfo != null) { v.add(new DERTaggedObject(true, 1, moreInfo)); } return new BERSequence(v); }
From source file:net.markenwerk.utils.mail.smime.SmimeUtil.java
License:Open Source License
private static ASN1EncodableVector getSignedAttributes(SmimeKey smimeKey) { ASN1EncodableVector signedAttributes = new ASN1EncodableVector(); IssuerAndSerialNumber issuerAndSerialNumber = getIssuerAndSerialNumber(smimeKey); signedAttributes.add(new SMIMEEncryptionKeyPreferenceAttribute(issuerAndSerialNumber)); signedAttributes.add(new SMIMECapabilitiesAttribute(getCapabilityVector())); return signedAttributes; }
From source file:net.ripe.rpki.commons.crypto.cms.manifest.ManifestCmsBuilder.java
License:BSD License
ASN1Encodable encodeFileList() { ASN1EncodableVector seq = new ASN1EncodableVector(); for (Map.Entry<String, byte[]> fileAndHash : files.entrySet()) { seq.add(encodeFileAndHash(fileAndHash.getKey(), fileAndHash.getValue())); }/*from w w w. j av a2s . c om*/ return new DERSequence(seq); }
From source file:net.schmizz.sshj.signature.SignatureDSA.java
License:Apache License
/** * Encodes the signature as a DER sequence (ASN.1 format). */// w w w .ja v a2 s . co m private byte[] asnEncode(byte[] sigBlob) throws IOException { byte[] r = new BigInteger(1, Arrays.copyOfRange(sigBlob, 0, 20)).toByteArray(); byte[] s = new BigInteger(1, Arrays.copyOfRange(sigBlob, 20, 40)).toByteArray(); ASN1EncodableVector vector = new ASN1EncodableVector(); vector.add(new ASN1Integer(r)); vector.add(new ASN1Integer(s)); ByteArrayOutputStream baos = new ByteArrayOutputStream(); ASN1OutputStream asnOS = new ASN1OutputStream(baos); asnOS.writeObject(new DERSequence(vector)); asnOS.flush(); return baos.toByteArray(); }
From source file:net.schmizz.sshj.signature.SignatureECDSA.java
License:Apache License
/** * Encodes the signature as a DER sequence (ASN.1 format). *///from w ww. j a v a 2 s.c om private byte[] asnEncode(byte[] sigBlob) throws IOException { Buffer.PlainBuffer sigbuf = new Buffer.PlainBuffer(sigBlob); byte[] r = sigbuf.readBytes(); byte[] s = sigbuf.readBytes(); ASN1EncodableVector vector = new ASN1EncodableVector(); vector.add(new ASN1Integer(r)); vector.add(new ASN1Integer(s)); ByteArrayOutputStream baos = new ByteArrayOutputStream(); ASN1OutputStream asnOS = new ASN1OutputStream(baos); asnOS.writeObject(new DERSequence(vector)); asnOS.flush(); return baos.toByteArray(); }
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 2 s .co m*/ 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);/*from w w w . j a v a2s .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 ww .jav a 2s.co m 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 . ja va 2 s . 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); } }