List of usage examples for org.bouncycastle.asn1 DERSequence getEncoded
public byte[] getEncoded() throws IOException
From source file:tr.gov.turkiye.esign.cms.SignerInfo.java
/** * Gets encoded bytes of authenticated attributes * @return byte array//from w ww . j a v a 2 s. com * @throws SmartCardException */ public byte[] getEncodedAuthenticatedAttributes() throws SmartCardException { try { final ByteArrayOutputStream bOut = new ByteArrayOutputStream(); final DEROutputStream dOut = new DEROutputStream(bOut); dOut.writeObject(getSignedAttributesSet()); final byte[] bytesToSign = bOut.toByteArray(); final byte[] bytesToSignHash = getHash(bytesToSign); ASN1EncodableVector v = new ASN1EncodableVector(); if (isSHA256) { v.add(ObjectID.idSHA256); } else { v.add(ObjectID.idSHA1); } v.add(DERNull.INSTANCE); final DERSequence algorithmIdentifier = new DERSequence(v); v = new ASN1EncodableVector(); v.add(algorithmIdentifier); v.add(new DEROctetString(bytesToSignHash)); final DERSequence digestInfo = new DERSequence(v); final byte[] bytes = digestInfo.getEncoded(); return bytes; } catch (IOException ex) { throw new SmartCardException(ExceptionSupport.getValue("IOException"), ex); } }