当前位置: 首页>>代码示例>>Java>>正文


Java DerOutputStream.write方法代码示例

本文整理汇总了Java中sun.security.util.DerOutputStream.write方法的典型用法代码示例。如果您正苦于以下问题:Java DerOutputStream.write方法的具体用法?Java DerOutputStream.write怎么用?Java DerOutputStream.write使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在sun.security.util.DerOutputStream的用法示例。


在下文中一共展示了DerOutputStream.write方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: getEncoded

import sun.security.util.DerOutputStream; //导入方法依赖的package包/类
/**
 * Returns the ASN.1 encoding of this object.
 * @return the ASN.1 encoding. Returns a new array
 * each time this method is called.
 * @exception IOException if error occurs when constructing its
 * ASN.1 encoding.
 */
public byte[] getEncoded() throws IOException {
    if (this.encoded == null) {
        DerOutputStream out = new DerOutputStream();
        DerOutputStream tmp = new DerOutputStream();

        // encode encryption algorithm
        algid.encode(tmp);

        // encode encrypted data
        tmp.putOctetString(encryptedData);

        // wrap everything into a SEQUENCE
        out.write(DerValue.tag_Sequence, tmp);
        this.encoded = out.toByteArray();
    }
    return this.encoded.clone();
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:25,代码来源:EncryptedPrivateKeyInfo.java

示例2: getEncoded

import sun.security.util.DerOutputStream; //导入方法依赖的package包/类
/**
 * Returns the ASN.1 encoding of this class.
 */
public byte[] getEncoded()
    throws IOException
{
    if (this.encoded != null) return this.encoded.clone();

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

    // encode encryption algorithm
    algid.encode(tmp);

    // encode encrypted data
    tmp.putOctetString(encryptedData);

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

    return this.encoded.clone();
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:24,代码来源:EncryptedPrivateKeyInfo.java

示例3: send

import sun.security.util.DerOutputStream; //导入方法依赖的package包/类
/**
 * Send the encoded {@code OCSPStatusRequest} out through the provided
 *      {@code HandshakeOutputStream}
 *
 * @param s the {@code HandshakeOutputStream} on which to send the encoded
 *      data
 *
 * @throws IOException if any encoding errors occur
 */
@Override
public void send(HandshakeOutStream s) throws IOException {
    s.putInt16(ridListLen);
    for (ResponderId rid : responderIds) {
        s.putBytes16(rid.getEncoded());
    }

    DerOutputStream seqOut = new DerOutputStream();
    DerOutputStream extBytes = new DerOutputStream();

    if (extensions.size() > 0) {
        for (Extension ext : extensions) {
            ext.encode(extBytes);
        }
        seqOut.write(DerValue.tag_Sequence, extBytes);
    }
    s.putBytes16(seqOut.toByteArray());
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:28,代码来源:OCSPStatusRequest.java

示例4: encodePKIPATH

import sun.security.util.DerOutputStream; //导入方法依赖的package包/类
/**
 * 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);
    }
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:36,代码来源:X509CertPath.java

示例5: encode

import sun.security.util.DerOutputStream; //导入方法依赖的package包/类
/**
 * Write the PolicyInformation to the DerOutputStream.
 *
 * @param out the DerOutputStream to write the extension to.
 * @exception IOException on encoding errors.
 */
public void encode(DerOutputStream out) throws IOException {
    DerOutputStream tmp = new DerOutputStream();
    policyIdentifier.encode(tmp);
    if (!policyQualifiers.isEmpty()) {
        DerOutputStream tmp2 = new DerOutputStream();
        for (PolicyQualifierInfo pq : policyQualifiers) {
            tmp2.write(pq.getEncoded());
        }
        tmp.write(DerValue.tag_Sequence, tmp2);
    }
    out.write(DerValue.tag_Sequence, tmp);
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:19,代码来源:PolicyInformation.java

示例6: getEncoded

import sun.security.util.DerOutputStream; //导入方法依赖的package包/类
/**
 * 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();
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:37,代码来源:MacData.java

示例7: encodeExtensions

import sun.security.util.DerOutputStream; //导入方法依赖的package包/类
private void encodeExtensions(DerOutputStream tbsStream)
        throws IOException {
    DerOutputStream extSequence = new DerOutputStream();
    DerOutputStream extItems = new DerOutputStream();

    for (Extension ext : responseExtensions.values()) {
        ext.encode(extItems);
    }
    extSequence.write(DerValue.tag_Sequence, extItems);
    tbsStream.write(DerValue.createTag(DerValue.TAG_CONTEXT, true,
            (byte)1), extSequence);
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:13,代码来源:SimpleOCSPServer.java

示例8: encodeThis

import sun.security.util.DerOutputStream; //导入方法依赖的package包/类
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();
    }
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:14,代码来源:AuthorityInfoAccessExtension.java

示例9: encode

import sun.security.util.DerOutputStream; //导入方法依赖的package包/类
public byte[] encode() throws IOException {

        DerOutputStream request = new DerOutputStream();

        // encode version
        request.putInteger(version);

        // encode messageImprint
        DerOutputStream messageImprint = new DerOutputStream();
        hashAlgorithmId.encode(messageImprint);
        messageImprint.putOctetString(hashValue);
        request.write(DerValue.tag_Sequence, messageImprint);

        // encode optional elements

        if (policyId != null) {
            request.putOID(new ObjectIdentifier(policyId));
        }
        if (nonce != null) {
            request.putInteger(nonce);
        }
        if (returnCertificate) {
            request.putBoolean(true);
        }

        DerOutputStream out = new DerOutputStream();
        out.write(DerValue.tag_Sequence, request);
        return out.toByteArray();
    }
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:30,代码来源:TSRequest.java

示例10: encodeBasicOcspResponse

import sun.security.util.DerOutputStream; //导入方法依赖的package包/类
private byte[] encodeBasicOcspResponse() throws IOException {
    DerOutputStream outerSeq = new DerOutputStream();
    DerOutputStream basicORItemStream = new DerOutputStream();

    // Encode the tbsResponse
    byte[] tbsResponseBytes = encodeTbsResponse();
    basicORItemStream.write(tbsResponseBytes);

    try {
        sigAlgId.derEncode(basicORItemStream);

        // Create the signature
        Signature sig = Signature.getInstance(sigAlgId.getName());
        sig.initSign(signerKey);
        sig.update(tbsResponseBytes);
        signature = sig.sign();
        basicORItemStream.putBitString(signature);
    } catch (GeneralSecurityException exc) {
        err(exc);
        throw new IOException(exc);
    }

    // Add certificates
    try {
        DerOutputStream certStream = new DerOutputStream();
        ArrayList<DerValue> certList = new ArrayList<>();
        if (signerCert != issuerCert) {
            certList.add(new DerValue(signerCert.getEncoded()));
        }
        certList.add(new DerValue(issuerCert.getEncoded()));
        DerValue[] dvals = new DerValue[certList.size()];
        certStream.putSequence(certList.toArray(dvals));
        basicORItemStream.write(DerValue.createTag(DerValue.TAG_CONTEXT,
                true, (byte)0), certStream);
    } catch (CertificateEncodingException cex) {
        err(cex);
        throw new IOException(cex);
    }

    // Commit the outermost sequence bytes
    outerSeq.write(DerValue.tag_Sequence, basicORItemStream);
    return outerSeq.toByteArray();
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:44,代码来源:SimpleOCSPServer.java

示例11: encodeThis

import sun.security.util.DerOutputStream; //导入方法依赖的package包/类
private void encodeThis() throws IOException {
    if (keyUsages == null || keyUsages.isEmpty()) {
        this.extensionValue = null;
        return;
    }
    DerOutputStream os = new DerOutputStream();
    DerOutputStream tmp = new DerOutputStream();

    for (int i = 0; i < keyUsages.size(); i++) {
        tmp.putOID(keyUsages.elementAt(i));
    }

    os.write(DerValue.tag_Sequence, tmp);
    this.extensionValue = os.toByteArray();
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:16,代码来源:ExtendedKeyUsageExtension.java

示例12: encodeThis

import sun.security.util.DerOutputStream; //导入方法依赖的package包/类
private void encodeThis() throws IOException {
    if (distributionPoints.isEmpty()) {
        this.extensionValue = null;
    } else {
        DerOutputStream pnts = new DerOutputStream();
        for (DistributionPoint point : distributionPoints) {
            point.encode(pnts);
        }
        DerOutputStream seq = new DerOutputStream();
        seq.write(DerValue.tag_Sequence, pnts);
        this.extensionValue = seq.toByteArray();
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:14,代码来源:CRLDistributionPointsExtension.java

示例13: encodeTbsCert

import sun.security.util.DerOutputStream; //导入方法依赖的package包/类
/**
 * Encode the bytes for the TBSCertificate structure:
 * <PRE>
 *  TBSCertificate  ::=  SEQUENCE  {
 *      version         [0]  EXPLICIT Version DEFAULT v1,
 *      serialNumber         CertificateSerialNumber,
 *      signature            AlgorithmIdentifier,
 *      issuer               Name,
 *      validity             Validity,
 *      subject              Name,
 *      subjectPublicKeyInfo SubjectPublicKeyInfo,
 *      issuerUniqueID  [1]  IMPLICIT UniqueIdentifier OPTIONAL,
 *                        -- If present, version MUST be v2 or v3
 *      subjectUniqueID [2]  IMPLICIT UniqueIdentifier OPTIONAL,
 *                        -- If present, version MUST be v2 or v3
 *      extensions      [3]  EXPLICIT Extensions OPTIONAL
 *                        -- If present, version MUST be v3
 *      }
 *
 * @param issuerCert The certificate of the issuing authority, or
 * {@code null} if the resulting certificate is self-signed.
 * @param signAlg The signature algorithm object
 *
 * @return The DER-encoded bytes for the TBSCertificate structure
 *
 * @throws IOException if an encoding error occurs.
 */
private byte[] encodeTbsCert(X509Certificate issuerCert,
        AlgorithmId signAlg) throws IOException {
    DerOutputStream tbsCertSeq = new DerOutputStream();
    DerOutputStream tbsCertItems = new DerOutputStream();

    // Hardcode to V3
    byte[] v3int = {0x02, 0x01, 0x02};
    tbsCertItems.write(DerValue.createTag(DerValue.TAG_CONTEXT, true,
            (byte)0), v3int);

    // Serial Number
    SerialNumber sn = new SerialNumber(serialNumber);
    sn.encode(tbsCertItems);

    // Algorithm ID
    signAlg.derEncode(tbsCertItems);

    // Issuer Name
    if (issuerCert != null) {
        tbsCertItems.write(
                issuerCert.getSubjectX500Principal().getEncoded());
    } else {
        // Self-signed
        tbsCertItems.write(subjectName.getEncoded());
    }

    // Validity period (set as UTCTime)
    DerOutputStream valSeq = new DerOutputStream();
    valSeq.putUTCTime(notBefore);
    valSeq.putUTCTime(notAfter);
    tbsCertItems.write(DerValue.tag_Sequence, valSeq);

    // Subject Name
    tbsCertItems.write(subjectName.getEncoded());

    // SubjectPublicKeyInfo
    tbsCertItems.write(publicKey.getEncoded());

    // TODO: Extensions!
    encodeExtensions(tbsCertItems);

    // Wrap it all up in a SEQUENCE and return the bytes
    tbsCertSeq.write(DerValue.tag_Sequence, tbsCertItems);
    return tbsCertSeq.toByteArray();
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:73,代码来源:CertificateBuilder.java

示例14: getBagAttributes

import sun.security.util.DerOutputStream; //导入方法依赖的package包/类
private byte[] getBagAttributes(String alias, byte[] keyId,
    ObjectIdentifier[] trustedUsage,
    Set<KeyStore.Entry.Attribute> attributes) throws IOException {

    byte[] localKeyID = null;
    byte[] friendlyName = null;
    byte[] trustedKeyUsage = null;

    // return null if all three attributes are null
    if ((alias == null) && (keyId == null) && (trustedKeyUsage == null)) {
        return null;
    }

    // SafeBag Attributes
    DerOutputStream bagAttrs = new DerOutputStream();

    // Encode the friendlyname oid.
    if (alias != null) {
        DerOutputStream bagAttr1 = new DerOutputStream();
        bagAttr1.putOID(PKCS9FriendlyName_OID);
        DerOutputStream bagAttrContent1 = new DerOutputStream();
        DerOutputStream bagAttrValue1 = new DerOutputStream();
        bagAttrContent1.putBMPString(alias);
        bagAttr1.write(DerValue.tag_Set, bagAttrContent1);
        bagAttrValue1.write(DerValue.tag_Sequence, bagAttr1);
        friendlyName = bagAttrValue1.toByteArray();
    }

    // Encode the localkeyId oid.
    if (keyId != null) {
        DerOutputStream bagAttr2 = new DerOutputStream();
        bagAttr2.putOID(PKCS9LocalKeyId_OID);
        DerOutputStream bagAttrContent2 = new DerOutputStream();
        DerOutputStream bagAttrValue2 = new DerOutputStream();
        bagAttrContent2.putOctetString(keyId);
        bagAttr2.write(DerValue.tag_Set, bagAttrContent2);
        bagAttrValue2.write(DerValue.tag_Sequence, bagAttr2);
        localKeyID = bagAttrValue2.toByteArray();
    }

    // Encode the trustedKeyUsage oid.
    if (trustedUsage != null) {
        DerOutputStream bagAttr3 = new DerOutputStream();
        bagAttr3.putOID(TrustedKeyUsage_OID);
        DerOutputStream bagAttrContent3 = new DerOutputStream();
        DerOutputStream bagAttrValue3 = new DerOutputStream();
        for (ObjectIdentifier usage : trustedUsage) {
            bagAttrContent3.putOID(usage);
        }
        bagAttr3.write(DerValue.tag_Set, bagAttrContent3);
        bagAttrValue3.write(DerValue.tag_Sequence, bagAttr3);
        trustedKeyUsage = bagAttrValue3.toByteArray();
    }

    DerOutputStream attrs = new DerOutputStream();
    if (friendlyName != null) {
        attrs.write(friendlyName);
    }
    if (localKeyID != null) {
        attrs.write(localKeyID);
    }
    if (trustedKeyUsage != null) {
        attrs.write(trustedKeyUsage);
    }

    if (attributes != null) {
        for (KeyStore.Entry.Attribute attribute : attributes) {
            String attributeName = attribute.getName();
            // skip friendlyName, localKeyId and trustedKeyUsage
            if (CORE_ATTRIBUTES[0].equals(attributeName) ||
                CORE_ATTRIBUTES[1].equals(attributeName) ||
                CORE_ATTRIBUTES[2].equals(attributeName)) {
                continue;
            }
            attrs.write(((PKCS12Attribute) attribute).getEncoded());
        }
    }

    bagAttrs.write(DerValue.tag_Set, attrs);
    return bagAttrs.toByteArray();
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:82,代码来源:PKCS12KeyStore.java


注:本文中的sun.security.util.DerOutputStream.write方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。