Example #1
0
 /**
  * Encodes a Checksum object. <xmp> Checksum ::= SEQUENCE { cksumtype [0] Int32, checksum [1]
  * OCTET STRING } </xmp>
  *
  * <p>This definition reflects the Network Working Group RFC 4120 specification available at <a
  * href="http://www.ietf.org/rfc/rfc4120.txt">http://www.ietf.org/rfc/rfc4120.txt</a>.
  *
  * @return byte array of enocded Checksum.
  * @exception Asn1Exception if an error occurs while decoding an ASN1 encoded data.
  * @exception IOException if an I/O error occurs while reading encoded data.
  */
 public byte[] asn1Encode() throws Asn1Exception, IOException {
   DerOutputStream bytes = new DerOutputStream();
   DerOutputStream temp = new DerOutputStream();
   temp.putInteger(BigInteger.valueOf(cksumType));
   bytes.write(DerValue.createTag(DerValue.TAG_CONTEXT, true, (byte) 0x00), temp);
   temp = new DerOutputStream();
   temp.putOctetString(checksum);
   bytes.write(DerValue.createTag(DerValue.TAG_CONTEXT, true, (byte) 0x01), temp);
   temp = new DerOutputStream();
   temp.write(DerValue.tag_Sequence, bytes);
   return temp.toByteArray();
 }
Example #2
0
 /** Construct a key from its components. Used by the KeyFactory. */
 ECPrivateKeyImpl(BigInteger s, ECParameterSpec params) throws InvalidKeyException {
   this.s = s;
   this.params = params;
   // generate the encoding
   algid = new AlgorithmId(AlgorithmId.EC_oid, ECParameters.getAlgorithmParameters(params));
   try {
     DerOutputStream out = new DerOutputStream();
     out.putInteger(1); // version 1
     byte[] privBytes = ECUtil.trimZeroes(s.toByteArray());
     out.putOctetString(privBytes);
     DerValue val = new DerValue(DerValue.tag_Sequence, out.toByteArray());
     key = val.toByteArray();
   } catch (IOException exc) {
     // should never occur
     throw new InvalidKeyException(exc);
   }
 }