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


Java DerInputStream.available方法代码示例

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


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

示例1: checkPKCS8Encoding

import sun.security.util.DerInputStream; //导入方法依赖的package包/类
@SuppressWarnings("fallthrough")
private static void checkPKCS8Encoding(byte[] encodedKey)
    throws IOException {
    DerInputStream in = new DerInputStream(encodedKey);
    DerValue[] values = in.getSequence(3);

    switch (values.length) {
    case 4:
        checkTag(values[3], DerValue.TAG_CONTEXT, "attributes");
        /* fall through */
    case 3:
        checkTag(values[0], DerValue.tag_Integer, "version");
        DerInputStream algid = values[1].toDerInputStream();
        algid.getOID();
        if (algid.available() != 0) {
            algid.getDerValue();
        }
        checkTag(values[2], DerValue.tag_OctetString, "privateKey");
        break;
    default:
        throw new IOException("invalid key encoding");
    }
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:24,代码来源:EncryptedPrivateKeyInfo.java

示例2: parseAlgParameters

import sun.security.util.DerInputStream; //导入方法依赖的package包/类
private AlgorithmParameters parseAlgParameters(ObjectIdentifier algorithm,
    DerInputStream in) throws IOException
{
    AlgorithmParameters algParams = null;
    try {
        DerValue params;
        if (in.available() == 0) {
            params = null;
        } else {
            params = in.getDerValue();
            if (params.tag == DerValue.tag_Null) {
               params = null;
            }
        }
        if (params != null) {
            if (algorithm.equals((Object)pbes2_OID)) {
                algParams = AlgorithmParameters.getInstance("PBES2");
            } else {
                algParams = AlgorithmParameters.getInstance("PBE");
            }
            algParams.init(params.toByteArray());
        }
    } catch (Exception e) {
       throw new IOException("parseAlgParameters failed: " +
                             e.getMessage(), e);
    }
    return algParams;
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:29,代码来源:PKCS12KeyStore.java

示例3: parseAlgParameters

import sun.security.util.DerInputStream; //导入方法依赖的package包/类
private AlgorithmParameters parseAlgParameters(ObjectIdentifier algorithm,
    DerInputStream in) throws IOException
{
    AlgorithmParameters algParams = null;
    try {
        DerValue params;
        if (in.available() == 0) {
            params = null;
        } else {
            params = in.getDerValue();
            if (params.tag == DerValue.tag_Null) {
               params = null;
            }
        }
        if (params != null) {
            if (algorithm.equals(pbes2_OID)) {
                algParams = AlgorithmParameters.getInstance("PBES2");
            } else {
                algParams = AlgorithmParameters.getInstance("PBE");
            }
            algParams.init(params.toByteArray());
        }
    } catch (Exception e) {
       throw new IOException("parseAlgParameters failed: " +
                             e.getMessage(), e);
    }
    return algParams;
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:29,代码来源:PKCS12KeyStore.java

示例4: IssuingDistributionPointExtension

import sun.security.util.DerInputStream; //导入方法依赖的package包/类
/**
 * Creates a critical IssuingDistributionPointExtension from its
 * DER-encoding.
 *
 * @param critical true if the extension is to be treated as critical.
 * @param value the DER-encoded value. It must be a <code>byte[]</code>.
 * @exception IOException on decoding error.
 */
public IssuingDistributionPointExtension(Boolean critical, Object value)
        throws IOException {
    this.extensionId = PKIXExtensions.IssuingDistributionPoint_Id;
    this.critical = critical.booleanValue();

    if (!(value instanceof byte[])) {
        throw new IOException("Illegal argument type");
    }

    extensionValue = (byte[])value;
    DerValue val = new DerValue(extensionValue);
    if (val.tag != DerValue.tag_Sequence) {
        throw new IOException("Invalid encoding for " +
                              "IssuingDistributionPointExtension.");
    }

    // All the elements in issuingDistributionPoint are optional
    if ((val.data == null) || (val.data.available() == 0)) {
        return;
    }

    DerInputStream in = val.data;
    while (in != null && in.available() != 0) {
        DerValue opt = in.getDerValue();

        if (opt.isContextSpecific(TAG_DISTRIBUTION_POINT) &&
            opt.isConstructed()) {
            distributionPoint =
                new DistributionPointName(opt.data.getDerValue());
        } else if (opt.isContextSpecific(TAG_ONLY_USER_CERTS) &&
                   !opt.isConstructed()) {
            opt.resetTag(DerValue.tag_Boolean);
            hasOnlyUserCerts = opt.getBoolean();
        } else if (opt.isContextSpecific(TAG_ONLY_CA_CERTS) &&
              !opt.isConstructed()) {
            opt.resetTag(DerValue.tag_Boolean);
            hasOnlyCACerts = opt.getBoolean();
        } else if (opt.isContextSpecific(TAG_ONLY_SOME_REASONS) &&
                   !opt.isConstructed()) {
            revocationReasons = new ReasonFlags(opt); // expects tag implicit
        } else if (opt.isContextSpecific(TAG_INDIRECT_CRL) &&
                   !opt.isConstructed()) {
            opt.resetTag(DerValue.tag_Boolean);
            isIndirectCRL = opt.getBoolean();
        } else if (opt.isContextSpecific(TAG_ONLY_ATTRIBUTE_CERTS) &&
                   !opt.isConstructed()) {
            opt.resetTag(DerValue.tag_Boolean);
            hasOnlyAttributeCerts = opt.getBoolean();
        } else {
            throw new IOException
                ("Invalid encoding of IssuingDistributionPoint");
        }
    }
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:63,代码来源:IssuingDistributionPointExtension.java

示例5: SignerInfo

import sun.security.util.DerInputStream; //导入方法依赖的package包/类
/**
 * Parses a PKCS#7 signer info.
 *
 * <p>This constructor is used only for backwards compatibility with
 * PKCS#7 blocks that were generated using JDK1.1.x.
 *
 * @param derin the ASN.1 encoding of the signer info.
 * @param oldStyle flag indicating whether or not the given signer info
 * is encoded according to JDK1.1.x.
 */
public SignerInfo(DerInputStream derin, boolean oldStyle)
    throws IOException, ParsingException
{
    // version
    version = derin.getBigInteger();

    // issuerAndSerialNumber
    DerValue[] issuerAndSerialNumber = derin.getSequence(2);
    byte[] issuerBytes = issuerAndSerialNumber[0].toByteArray();
    issuerName = new X500Name(new DerValue(DerValue.tag_Sequence,
                                           issuerBytes));
    certificateSerialNumber = issuerAndSerialNumber[1].getBigInteger();

    // digestAlgorithmId
    DerValue tmp = derin.getDerValue();

    digestAlgorithmId = AlgorithmId.parse(tmp);

    // authenticatedAttributes
    if (oldStyle) {
        // In JDK1.1.x, the authenticatedAttributes are always present,
        // encoded as an empty Set (Set of length zero)
        derin.getSet(0);
    } else {
        // check if set of auth attributes (implicit tag) is provided
        // (auth attributes are OPTIONAL)
        if ((byte)(derin.peekByte()) == (byte)0xA0) {
            authenticatedAttributes = new PKCS9Attributes(derin);
        }
    }

    // digestEncryptionAlgorithmId - little RSA naming scheme -
    // signature == encryption...
    tmp = derin.getDerValue();

    digestEncryptionAlgorithmId = AlgorithmId.parse(tmp);

    // encryptedDigest
    encryptedDigest = derin.getOctetString();

    // unauthenticatedAttributes
    if (oldStyle) {
        // In JDK1.1.x, the unauthenticatedAttributes are always present,
        // encoded as an empty Set (Set of length zero)
        derin.getSet(0);
    } else {
        // check if set of unauth attributes (implicit tag) is provided
        // (unauth attributes are OPTIONAL)
        if (derin.available() != 0
            && (byte)(derin.peekByte()) == (byte)0xA1) {
            unauthenticatedAttributes =
                new PKCS9Attributes(derin, true);// ignore unsupported attrs
        }
    }

    // all done
    if (derin.available() != 0) {
        throw new ParsingException("extra data at the end");
    }
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:71,代码来源:SignerInfo.java

示例6: engineVerify

import sun.security.util.DerInputStream; //导入方法依赖的package包/类
/**
 * Verify all the data thus far updated.
 *
 * @param signature the alledged signature, encoded using the
 * Canonical Encoding Rules, as a sequence of integers, r and s.
 *
 * @param offset the offset to start from in the array of bytes.
 *
 * @param length the number of bytes to use, starting at offset.
 *
 * @exception SignatureException if the signature object was not
 * properly initialized, or if another exception occurs.
 *
 * @see sun.security.DSA#engineUpdate
 * @see sun.security.DSA#engineSign
 */
protected boolean engineVerify(byte[] signature, int offset, int length)
        throws SignatureException {

    BigInteger r = null;
    BigInteger s = null;
    // first decode the signature.
    try {
        // Enforce strict DER checking for signatures
        DerInputStream in =
            new DerInputStream(signature, offset, length, false);
        DerValue[] values = in.getSequence(2);

        // check number of components in the read sequence
        // and trailing data
        if ((values.length != 2) || (in.available() != 0)) {
            throw new IOException("Invalid encoding for signature");
        }
        r = values[0].getBigInteger();
        s = values[1].getBigInteger();
    } catch (IOException e) {
        throw new SignatureException("Invalid encoding for signature", e);
    }

    // some implementations do not correctly encode values in the ASN.1
    // 2's complement format. force r and s to be positive in order to
    // to validate those signatures
    if (r.signum() < 0) {
        r = new BigInteger(1, r.toByteArray());
    }
    if (s.signum() < 0) {
        s = new BigInteger(1, s.toByteArray());
    }

    if ((r.compareTo(presetQ) == -1) && (s.compareTo(presetQ) == -1)) {
        BigInteger w = generateW(presetP, presetQ, presetG, s);
        BigInteger v = generateV(presetY, presetP, presetQ, presetG, w, r);
        return v.equals(r);
    } else {
        throw new SignatureException("invalid signature: out of range values");
    }
}
 
开发者ID:JetBrains,项目名称:jdk8u_jdk,代码行数:58,代码来源:DSA.java


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