/** 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(); }
/** * Returns the encoded SPNEGO token Note: inserts the required CHOICE tags * * @return the encoded token * @exception GSSException */ byte[] getEncoded() throws IOException, GSSException { // get the token encoded value DerOutputStream token = new DerOutputStream(); token.write(encode()); // now insert the CHOICE switch (tokenType) { case NEG_TOKEN_INIT_ID: // Insert CHOICE of Negotiation Token DerOutputStream initToken = new DerOutputStream(); initToken.write( DerValue.createTag(DerValue.TAG_CONTEXT, true, (byte) NEG_TOKEN_INIT_ID), token); return initToken.toByteArray(); case NEG_TOKEN_TARG_ID: // Insert CHOICE of Negotiation Token DerOutputStream targToken = new DerOutputStream(); targToken.write( DerValue.createTag(DerValue.TAG_CONTEXT, true, (byte) NEG_TOKEN_TARG_ID), token); return targToken.toByteArray(); default: return token.toByteArray(); } }
/** * Encode the CertPath using PKIPATH format. * * @return a byte array containing the binary encoding of the PkiPath object * @exception CertificateEncodingException if an exception occurs */ private byte[] encodePKIPATH() throws CertificateEncodingException { ListIterator<X509Certificate> li = certs.listIterator(certs.size()); try { DerOutputStream bytes = new DerOutputStream(); // encode certs in reverse order (trust anchor to target) // according to PkiPath format while (li.hasPrevious()) { X509Certificate cert = li.previous(); // check for duplicate cert if (certs.lastIndexOf(cert) != certs.indexOf(cert)) { throw new CertificateEncodingException("Duplicate Certificate"); } // get encoded certificates byte[] encoded = cert.getEncoded(); bytes.write(encoded); } // Wrap the data in a SEQUENCE DerOutputStream derout = new DerOutputStream(); derout.write(DerValue.tag_SequenceOf, bytes); return derout.toByteArray(); } catch (IOException ioe) { throw new CertificateEncodingException("IOException encoding " + "PkiPath data: " + ioe, ioe); } }
/** * 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(); }
/** * Write the extension to the DerOutputStream. * * @param out the DerOutputStream to write the extension to. * @exception IOException on encoding errors. */ public void encode(OutputStream out) throws IOException { DerOutputStream tmp = new DerOutputStream(); if (this.extensionValue == null) { this.extensionId = PKIXExtensions.SubjectInfoAccess_Id; this.critical = false; encodeThis(); } super.encode(tmp); out.write(tmp.toByteArray()); }
/** * Write the extension to the DerOutputStream. * * @param out the DerOutputStream to write the extension to. * @exception IOException on encoding errors. */ public void encode(OutputStream out) throws IOException { DerOutputStream tmp = new DerOutputStream(); if (extensionValue == null) { extensionId = PKIXExtensions.CertificatePolicies_Id; critical = false; encodeThis(); } super.encode(tmp); out.write(tmp.toByteArray()); }
/** * Return the DER encoded form of the certificate pair. * * @return The encoded form of the certificate pair. * @throws CerticateEncodingException If an encoding exception occurs. */ public byte[] getEncoded() throws CertificateEncodingException { try { if (encoded == null) { DerOutputStream tmp = new DerOutputStream(); emit(tmp); encoded = tmp.toByteArray(); } } catch (IOException ex) { throw new CertificateEncodingException(ex.toString()); } return encoded; }
// Encode this extension value private void encodeThis() throws IOException { if (accessDescriptions.isEmpty()) { this.extensionValue = null; } else { DerOutputStream ads = new DerOutputStream(); for (AccessDescription accessDescription : accessDescriptions) { accessDescription.encode(ads); } DerOutputStream seq = new DerOutputStream(); seq.write(DerValue.tag_Sequence, ads); this.extensionValue = seq.toByteArray(); } }
/** Write the extension to the DerOutputStream. (Also called by the subclass) */ protected void encode(OutputStream out, ObjectIdentifier extensionId, boolean isCritical) throws IOException { DerOutputStream tmp = new DerOutputStream(); if (this.extensionValue == null) { this.extensionId = extensionId; this.critical = isCritical; encodeThis(); } super.encode(tmp); out.write(tmp.toByteArray()); }
/* */ public byte[] asn1Encode() /* */ throws Asn1Exception, IOException /* */ { /* 182 */ DerOutputStream localDerOutputStream1 = new DerOutputStream(); /* 183 */ DerOutputStream localDerOutputStream2 = new DerOutputStream(); /* 184 */ localDerOutputStream1.write( DerValue.createTag((byte) -128, true, (byte) 0), this.flags.asn1Encode()); /* */ /* 186 */ localDerOutputStream1.write( DerValue.createTag((byte) -128, true, (byte) 1), this.key.asn1Encode()); /* */ /* 188 */ localDerOutputStream1.write( DerValue.createTag((byte) -128, true, (byte) 2), this.crealm.asn1Encode()); /* */ /* 190 */ localDerOutputStream1.write( DerValue.createTag((byte) -128, true, (byte) 3), this.cname.asn1Encode()); /* */ /* 192 */ localDerOutputStream1.write( DerValue.createTag((byte) -128, true, (byte) 4), this.transited.asn1Encode()); /* */ /* 194 */ localDerOutputStream1.write( DerValue.createTag((byte) -128, true, (byte) 5), this.authtime.asn1Encode()); /* */ /* 196 */ if (this.starttime != null) { /* 197 */ localDerOutputStream1.write( DerValue.createTag((byte) -128, true, (byte) 6), this.starttime.asn1Encode()); /* */ } /* */ /* 200 */ localDerOutputStream1.write( DerValue.createTag((byte) -128, true, (byte) 7), this.endtime.asn1Encode()); /* */ /* 203 */ if (this.renewTill != null) { /* 204 */ localDerOutputStream1.write( DerValue.createTag((byte) -128, true, (byte) 8), this.renewTill.asn1Encode()); /* */ } /* */ /* 208 */ if (this.caddr != null) { /* 209 */ localDerOutputStream1.write( DerValue.createTag((byte) -128, true, (byte) 9), this.caddr.asn1Encode()); /* */ } /* */ /* 213 */ if (this.authorizationData != null) { /* 214 */ localDerOutputStream1.write( DerValue.createTag((byte) -128, true, (byte) 10), this.authorizationData.asn1Encode()); /* */ } /* */ /* 217 */ localDerOutputStream2.write((byte) 48, localDerOutputStream1); /* 218 */ localDerOutputStream1 = new DerOutputStream(); /* 219 */ localDerOutputStream1.write( DerValue.createTag((byte) 64, true, (byte) 3), localDerOutputStream2); /* */ /* 221 */ return localDerOutputStream1.toByteArray(); /* */ }
/** * 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(); /* */ }
/** * Encode the CertPath using PKCS#7 format. * * @return a byte array containing the binary encoding of the PKCS#7 object * @exception CertificateEncodingException if an exception occurs */ private byte[] encodePKCS7() throws CertificateEncodingException { PKCS7 p7 = new PKCS7( new AlgorithmId[0], new ContentInfo(ContentInfo.DATA_OID, null), certs.toArray(new X509Certificate[certs.size()]), new SignerInfo[0]); DerOutputStream derout = new DerOutputStream(); try { p7.encodeSignedData(derout); } catch (IOException ioe) { throw new CertificateEncodingException(ioe.getMessage()); } return derout.toByteArray(); }
// Encode this extension value. private void encodeThis() throws IOException { if (certPolicies == null || certPolicies.isEmpty()) { this.extensionValue = null; } else { DerOutputStream os = new DerOutputStream(); DerOutputStream tmp = new DerOutputStream(); for (PolicyInformation info : certPolicies) { info.encode(tmp); } os.write(DerValue.tag_Sequence, tmp); this.extensionValue = os.toByteArray(); } }
/* */ private NamedCurve( String paramString, ObjectIdentifier paramObjectIdentifier, EllipticCurve paramEllipticCurve, ECPoint paramECPoint, BigInteger paramBigInteger, int paramInt) /* */ throws IOException /* */ { /* 58 */ super(paramEllipticCurve, paramECPoint, paramBigInteger, paramInt); /* 59 */ this.name = paramString; /* 60 */ this.oid = paramObjectIdentifier; /* */ /* 62 */ DerOutputStream localDerOutputStream = new DerOutputStream(); /* 63 */ localDerOutputStream.putOID(paramObjectIdentifier); /* 64 */ this.encoded = localDerOutputStream.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(); }
/** 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); } }
/* */ public void encode(OutputStream paramOutputStream) /* */ throws IOException /* */ { /* 151 */ if ((this.notBefore == null) || (this.notAfter == null)) { /* 152 */ throw new IOException("CertAttrSet:CertificateValidity: null values to encode.\n"); /* */ } /* */ /* 155 */ DerOutputStream localDerOutputStream1 = new DerOutputStream(); /* */ /* 157 */ if (this.notBefore.getTime() < 2524636800000L) /* 158 */ localDerOutputStream1.putUTCTime(this.notBefore); /* */ else { /* 160 */ localDerOutputStream1.putGeneralizedTime(this.notBefore); /* */ } /* 162 */ if (this.notAfter.getTime() < 2524636800000L) /* 163 */ localDerOutputStream1.putUTCTime(this.notAfter); /* */ else { /* 165 */ localDerOutputStream1.putGeneralizedTime(this.notAfter); /* */ } /* 167 */ DerOutputStream localDerOutputStream2 = new DerOutputStream(); /* 168 */ localDerOutputStream2.write((byte) 48, localDerOutputStream1); /* */ /* 170 */ paramOutputStream.write(localDerOutputStream2.toByteArray()); /* */ }
/** * Encodes an EncTicketPart object. * * @return byte array of encoded EncTicketPart 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(); bytes.write(DerValue.createTag(DerValue.TAG_CONTEXT, true, (byte) 0x00), flags.asn1Encode()); bytes.write(DerValue.createTag(DerValue.TAG_CONTEXT, true, (byte) 0x01), key.asn1Encode()); bytes.write( DerValue.createTag(DerValue.TAG_CONTEXT, true, (byte) 0x02), cname.getRealm().asn1Encode()); bytes.write(DerValue.createTag(DerValue.TAG_CONTEXT, true, (byte) 0x03), cname.asn1Encode()); bytes.write( DerValue.createTag(DerValue.TAG_CONTEXT, true, (byte) 0x04), transited.asn1Encode()); bytes.write(DerValue.createTag(DerValue.TAG_CONTEXT, true, (byte) 0x05), authtime.asn1Encode()); if (starttime != null) { bytes.write( DerValue.createTag(DerValue.TAG_CONTEXT, true, (byte) 0x06), starttime.asn1Encode()); } bytes.write(DerValue.createTag(DerValue.TAG_CONTEXT, true, (byte) 0x07), endtime.asn1Encode()); if (renewTill != null) { bytes.write( DerValue.createTag(DerValue.TAG_CONTEXT, true, (byte) 0x08), renewTill.asn1Encode()); } if (caddr != null) { bytes.write(DerValue.createTag(DerValue.TAG_CONTEXT, true, (byte) 0x09), caddr.asn1Encode()); } if (authorizationData != null) { bytes.write( DerValue.createTag(DerValue.TAG_CONTEXT, true, (byte) 0x0A), authorizationData.asn1Encode()); } temp.write(DerValue.tag_Sequence, bytes); bytes = new DerOutputStream(); bytes.write(DerValue.createTag(DerValue.TAG_APPLICATION, true, (byte) 0x03), temp); return bytes.toByteArray(); }
/** * Encodes a Realm object. * * @return the byte array of encoded KrbCredInfo 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 out = new DerOutputStream(); out.putDerValue(new KerberosString(this.realm).toDerValue()); return out.toByteArray(); }