Beispiel #1
0
  /** Get the encoding of the key. */
  public synchronized byte[] getEncoded() {
    if (this.encodedKey == null) {
      try {
        DerOutputStream algid = new DerOutputStream();

        // store oid in algid
        algid.putOID(new ObjectIdentifier(DH_data));

        // encode parameters
        DerOutputStream params = new DerOutputStream();
        params.putInteger(this.p);
        params.putInteger(this.g);
        if (this.l != 0) params.putInteger(this.l);
        // wrap parameters into SEQUENCE
        DerValue paramSequence = new DerValue(DerValue.tag_Sequence, params.toByteArray());
        // store parameter SEQUENCE in algid
        algid.putDerValue(paramSequence);

        // wrap algid into SEQUENCE, and store it in key encoding
        DerOutputStream tmpDerKey = new DerOutputStream();
        tmpDerKey.write(DerValue.tag_Sequence, algid);

        // store key data
        tmpDerKey.putBitString(this.key);

        // wrap algid and key into SEQUENCE
        DerOutputStream derKey = new DerOutputStream();
        derKey.write(DerValue.tag_Sequence, tmpDerKey);
        this.encodedKey = derKey.toByteArray();
      } catch (IOException e) {
        return null;
      }
    }
    return (byte[]) this.encodedKey.clone();
  }
Beispiel #2
0
  /**
   * Returns the ASN.1 encoding of this object.
   *
   * @return the ASN.1 encoding.
   * @exception IOException if error occurs when constructing its ASN.1 encoding.
   */
  public byte[] getEncoded() throws NoSuchAlgorithmException, IOException {
    if (this.encoded != null) return this.encoded.clone();

    DerOutputStream out = new DerOutputStream();
    DerOutputStream tmp = new DerOutputStream();

    DerOutputStream tmp2 = new DerOutputStream();
    // encode encryption algorithm
    AlgorithmId algid = AlgorithmId.get(digestAlgorithmName);
    algid.encode(tmp2);

    // encode digest data
    tmp2.putOctetString(digest);

    tmp.write(DerValue.tag_Sequence, tmp2);

    // encode salt
    tmp.putOctetString(macSalt);

    // encode iterations
    tmp.putInteger(iterations);

    // wrap everything into a SEQUENCE
    out.write(DerValue.tag_Sequence, tmp);
    this.encoded = out.toByteArray();

    return this.encoded.clone();
  }
 // Encode this extension value
 private void encodeThis() throws IOException {
   if (crlNumber == null) {
     this.extensionValue = null;
     return;
   }
   DerOutputStream os = new DerOutputStream();
   os.putInteger(this.crlNumber);
   this.extensionValue = os.toByteArray();
 }
Beispiel #4
0
 /** Construct a key from its components. Used by the RSAKeyFactory and the RSAKeyPairGenerator. */
 RSAPrivateCrtKeyImpl(
     BigInteger n,
     BigInteger e,
     BigInteger d,
     BigInteger p,
     BigInteger q,
     BigInteger pe,
     BigInteger qe,
     BigInteger coeff)
     throws InvalidKeyException {
   this.n = n;
   this.e = e;
   this.d = d;
   this.p = p;
   this.q = q;
   this.pe = pe;
   this.qe = qe;
   this.coeff = coeff;
   RSAKeyFactory.checkRSAProviderKeyLengths(n.bitLength(), e);
   // generate the encoding
   algid = rsaId;
   try {
     DerOutputStream out = new DerOutputStream();
     out.putInteger(0); // version must be 0
     out.putInteger(n);
     out.putInteger(e);
     out.putInteger(d);
     out.putInteger(p);
     out.putInteger(q);
     out.putInteger(pe);
     out.putInteger(qe);
     out.putInteger(coeff);
     DerValue val = new DerValue(DerValue.tag_Sequence, out.toByteArray());
     key = val.toByteArray();
   } catch (IOException exc) {
     // should never occur
     throw new InvalidKeyException(exc);
   }
 }
Beispiel #5
0
  /**
   * Encodes an MethodData object.
   *
   * @return the byte array of encoded MethodData object.
   * @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(methodType));
    bytes.write(DerValue.createTag(DerValue.TAG_CONTEXT, true, (byte) 0x00), temp);
    if (methodData != null) {
      temp = new DerOutputStream();
      temp.putOctetString(methodData);
      bytes.write(DerValue.createTag(DerValue.TAG_CONTEXT, true, (byte) 0x01), temp);
    }

    temp = new DerOutputStream();
    temp.write(DerValue.tag_Sequence, bytes);
    return temp.toByteArray();
  }
 /*     */ public byte[] asn1Encode() /*     */ throws Asn1Exception, IOException /*     */ {
   /* 104 */ DerOutputStream localDerOutputStream1 = new DerOutputStream();
   /* 105 */ DerOutputStream localDerOutputStream2 = new DerOutputStream();
   /* 106 */ localDerOutputStream1.write(
       DerValue.createTag((byte) -128, true, (byte) 0), this.pATimeStamp.asn1Encode());
   /* 107 */ if (this.pAUSec != null) {
     /* 108 */ localDerOutputStream2 = new DerOutputStream();
     /* 109 */ localDerOutputStream2.putInteger(BigInteger.valueOf(this.pAUSec.intValue()));
     /* 110 */ localDerOutputStream1.write(
         DerValue.createTag((byte) -128, true, (byte) 1), localDerOutputStream2);
     /*     */ }
   /* 112 */ localDerOutputStream2 = new DerOutputStream();
   /* 113 */ localDerOutputStream2.write((byte) 48, localDerOutputStream1);
   /* 114 */ return localDerOutputStream2.toByteArray();
   /*     */ }
 /**
  * Encodes a <code>PrincipalName</code> object. Note that only the type and names are encoded. To
  * encode the realm, call getRealm().asn1Encode().
  *
  * @return the byte array of the encoded PrncipalName object.
  * @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();
   BigInteger bint = BigInteger.valueOf(this.nameType);
   temp.putInteger(bint);
   bytes.write(DerValue.createTag(DerValue.TAG_CONTEXT, true, (byte) 0x00), temp);
   temp = new DerOutputStream();
   DerValue der[] = new DerValue[nameStrings.length];
   for (int i = 0; i < nameStrings.length; i++) {
     der[i] = new KerberosString(nameStrings[i]).toDerValue();
   }
   temp.putSequence(der);
   bytes.write(DerValue.createTag(DerValue.TAG_CONTEXT, true, (byte) 0x01), temp);
   temp = new DerOutputStream();
   temp.write(DerValue.tag_Sequence, bytes);
   return temp.toByteArray();
 }
 /*     */ public void putInteger(Integer paramInteger) /*     */ throws IOException /*     */ {
   /* 175 */ putInteger(paramInteger.intValue());
   /*     */ }