List of usage examples for org.bouncycastle.asn1 DERSequence getEncoded
public byte[] getEncoded(String encoding) throws IOException
From source file:de.tsenger.sandbox.CardSecurityParser.java
License:Open Source License
/** * @param args// ww w. ja va 2 s. c om * @throws Exception */ public static void main(String[] args) throws Exception { byte[] efcsBytes = readBinaryFile("/home/tsenger/Desktop/EFCardSecurity.bin"); ASN1Sequence asnSeq = (ASN1Sequence) ASN1Sequence.fromByteArray(efcsBytes); ContentInfo contentInfo = ContentInfo.getInstance(asnSeq); System.out.println(contentInfo.getContentType()); DERSequence derSeq = (DERSequence) contentInfo.getContent(); System.out.println(HexString.bufferToHex(derSeq.getEncoded(null))); SignedData signedData = SignedData.getInstance(derSeq); System.out.println("CMSVersion: " + signedData.getVersion().getValue().intValue()); ContentInfo contentInfo2 = signedData.getEncapContentInfo(); System.out.println(contentInfo2.getContentType()); DEROctetString octString = (DEROctetString) contentInfo2.getContent(); System.out.println("OctetString:\n" + HexString.bufferToHex(octString.getEncoded(null))); System.out.println("OctetString:\n" + HexString.bufferToHex(octString.getOctets())); SecurityInfos si = new SecurityInfos(); si.decode(octString.getOctets()); System.out.println(si); byte[] parameter = si.getChipAuthenticationPublicKeyInfoList().get(0).getPublicKey().getPublicKey(); System.out.println(HexString.bufferToHex(parameter)); System.out.println("Key Referenz: " + si.getChipAuthenticationPublicKeyInfoList().get(0).getKeyId()); System.out.println("CA OID: " + si.getChipAuthenticationPublicKeyInfoList().get(0).getPublicKey().getAlgorithm().getAlgorithm()); }
From source file:ee.ria.xroad.common.hashchain.DigestList.java
License:Open Source License
/** * Takes as input a sequence of hashes and combines them using DigestList * data structure.// ww w .ja v a2 s. c o m */ static byte[] concatDigests(String digestMethodUri, byte[]... items) throws Exception { ASN1Encodable[] digestList = new ASN1Encodable[items.length]; for (int i = 0; i < items.length; ++i) { digestList[i] = singleDigest(digestMethodUri, items[i]); } DERSequence step = new DERSequence(digestList); return step.getEncoded(DER); }
From source file:ee.ria.xroad.common.hashchain.DigestList.java
License:Open Source License
/** * Takes as input a sequence of hashes and combines them using DigestList * data structure./* w w w .j a va 2 s .c om*/ */ static byte[] concatDigests(DigestValue... items) throws Exception { ASN1Encodable[] digestList = new ASN1Encodable[items.length]; for (int i = 0; i < items.length; ++i) { digestList[i] = singleDigest(items[i].getDigestMethod(), items[i].getDigestValue()); } DERSequence step = new DERSequence(digestList); return step.getEncoded(DER); }
From source file:eu.emi.security.authn.x509.helpers.proxy.X509v3CertificateBuilder.java
License:Open Source License
private X509Certificate sign(TBSCertificate toSign, AlgorithmIdentifier sigAlg, String sigAlgName, PrivateKey key, String provider, SecureRandom random) throws InvalidKeyException, NoSuchProviderException, NoSuchAlgorithmException, SignatureException, IOException, CertificateParsingException { byte[] signature = calculateSignature(sigAlgName, provider, key, random, toSign); ASN1EncodableVector v = new ASN1EncodableVector(); v.add(toSign);// w ww. j ava 2 s . co m v.add(sigAlg.toASN1Primitive()); v.add(new DERBitString(signature)); DERSequence derCertificate = new DERSequence(v); CertificateFactory factory; try { factory = CertificateFactory.getInstance("X.509"); ByteArrayInputStream bais = new ByteArrayInputStream(derCertificate.getEncoded(ASN1Encoding.DER)); return (X509Certificate) factory.generateCertificate(bais); } catch (CertificateException e) { throw new RuntimeException("The generated proxy " + "certificate was not parsed by the JDK", e); } }
From source file:net.sf.keystore_explorer.crypto.csr.spkac.Spkac.java
License:Open Source License
private byte[] encodeRsaPublicKeyAsBitString(RSAPublicKey rsaPublicKey) throws SpkacException { try {//from w w w .ja v a2 s. com 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); } }