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


Java ASN1InputStream类代码示例

本文整理汇总了Java中org.bouncycastle.asn1.ASN1InputStream的典型用法代码示例。如果您正苦于以下问题:Java ASN1InputStream类的具体用法?Java ASN1InputStream怎么用?Java ASN1InputStream使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


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

示例1: generateSignatureBlock

import org.bouncycastle.asn1.ASN1InputStream; //导入依赖的package包/类
private static byte[] generateSignatureBlock(
        SignerConfig signerConfig, byte[] signatureFileBytes)
                throws InvalidKeyException, CertificateEncodingException, SignatureException {
    JcaCertStore certs = new JcaCertStore(signerConfig.certificates);
    X509Certificate signerCert = signerConfig.certificates.get(0);
    String jcaSignatureAlgorithm =
            getJcaSignatureAlgorithm(
                    signerCert.getPublicKey(), signerConfig.signatureDigestAlgorithm);
    try {
        ContentSigner signer =
                new JcaContentSignerBuilder(jcaSignatureAlgorithm)
                .build(signerConfig.privateKey);
        CMSSignedDataGenerator gen = new CMSSignedDataGenerator();
        gen.addSignerInfoGenerator(
                new SignerInfoGeneratorBuilder(
                        new JcaDigestCalculatorProviderBuilder().build(),
                        SignerInfoSignatureAlgorithmFinder.INSTANCE)
                        .setDirectSignature(true)
                        .build(signer, new JcaX509CertificateHolder(signerCert)));
        gen.addCertificates(certs);

        CMSSignedData sigData =
                gen.generate(new CMSProcessableByteArray(signatureFileBytes), false);

        ByteArrayOutputStream out = new ByteArrayOutputStream();
        try (ASN1InputStream asn1 = new ASN1InputStream(sigData.getEncoded())) {
            DEROutputStream dos = new DEROutputStream(out);
            dos.writeObject(asn1.readObject());
        }
        return out.toByteArray();
    } catch (OperatorCreationException | CMSException | IOException e) {
        throw new SignatureException("Failed to generate signature", e);
    }
}
 
开发者ID:Meituan-Dianping,项目名称:walle,代码行数:35,代码来源:V1SchemeSigner.java

示例2: readPrivateKey

import org.bouncycastle.asn1.ASN1InputStream; //导入依赖的package包/类
/** Read a PKCS#8 format private key. */
private static PrivateKey readPrivateKey(InputStream input)
throws IOException, GeneralSecurityException {
    try {
        byte[] buffer = new byte[4096];
        int size = input.read(buffer);
        byte[] bytes = Arrays.copyOf(buffer, size);
        /* Check to see if this is in an EncryptedPrivateKeyInfo structure. */
        PKCS8EncodedKeySpec spec = new PKCS8EncodedKeySpec(bytes);
        /*
         * Now it's in a PKCS#8 PrivateKeyInfo structure. Read its Algorithm
         * OID and use that to construct a KeyFactory.
         */
        ASN1InputStream bIn = new ASN1InputStream(new ByteArrayInputStream(spec.getEncoded()));
        PrivateKeyInfo pki = PrivateKeyInfo.getInstance(bIn.readObject());
        String algOid = pki.getPrivateKeyAlgorithm().getAlgorithm().getId();
        return KeyFactory.getInstance(algOid).generatePrivate(spec);
    } finally {
        input.close();
    }
}
 
开发者ID:bhb27,项目名称:isu,代码行数:22,代码来源:ZipUtils.java

示例3: parseDG1

import org.bouncycastle.asn1.ASN1InputStream; //导入依赖的package包/类
private void parseDG1(byte[] DG1) {
    try {
        ASN1InputStream bIn = new ASN1InputStream(DG1);
        org.bouncycastle.asn1.DERApplicationSpecific app = (DERApplicationSpecific) bIn.readObject();

        ASN1Sequence seq = (ASN1Sequence) app.getObject(BERTags.SEQUENCE);
        Enumeration secEnum = seq.getObjects();
        while (secEnum.hasMoreElements()) {
            ASN1Primitive seqObj = (ASN1Primitive) secEnum.nextElement();
            byte[] data = seqObj.getEncoded();
            if (data[0]== 0x41) {
                Log.d("type approval number", ByteUtils.bytesToHex(data));
                this.set5F01(data);
            } else if (data[0] == 0x42) {
                byte[] input = Arrays.copyOfRange(data, 3, data.length);
                parse5F02(input);
            } else if (data[0] == 0x7F) {
                parse7F63(data);
            }
        }
        bIn.close();
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
}
 
开发者ID:mDL-ILP,项目名称:mDL-ILP,代码行数:27,代码来源:DrivingLicence.java

示例4: parseNonce

import org.bouncycastle.asn1.ASN1InputStream; //导入依赖的package包/类
private byte[] parseNonce(byte[] data) {
    try (ASN1InputStream bIn = new ASN1InputStream(data)) {
        DERApplicationSpecific app = (DERApplicationSpecific) bIn.readObject();

        ASN1Sequence seq = (ASN1Sequence) app.getObject(BERTags.SEQUENCE);

        byte[] tag80 = ((ASN1Primitive) seq.getObjects().nextElement()).getEncoded();

        if (tag80[0] == (byte) 0x80) {

            MessageDigest md = MessageDigest.getInstance("SHA-256");
            byte[] kpi =  md.digest(Bytes.concatenate(CAN.getBytes(), Bytes.bytes("00 00 00 03")));

            return AESUtils.decryptAESCBC(Bytes.allButFirst(tag80, 2), kpi);
        }
    } catch (IOException | NoSuchAlgorithmException e) {
        Log.e(getClass().getName(), "Failed to parse nonce from response data", e);
    }

    return null;
}
 
开发者ID:mDL-ILP,项目名称:mDL-ILP,代码行数:22,代码来源:PACEAPDUInterface.java

示例5: getAlgorithmIdentifier

import org.bouncycastle.asn1.ASN1InputStream; //导入依赖的package包/类
protected static AlgorithmIdentifier getAlgorithmIdentifier(
    PublicKey key)
    throws CertPathValidatorException
{
    try
    {
        ASN1InputStream aIn = new ASN1InputStream(key.getEncoded());

        SubjectPublicKeyInfo info = SubjectPublicKeyInfo.getInstance(aIn.readObject());

        return info.getAlgorithmId();
    }
    catch (Exception e)
    {
        throw new ExtCertPathValidatorException("Subject public key cannot be decoded.", e);
    }
}
 
开发者ID:Appdome,项目名称:ipack,代码行数:18,代码来源:CertPathValidatorUtilities.java

示例6: parseDG11

import org.bouncycastle.asn1.ASN1InputStream; //导入依赖的package包/类
private void parseDG11(byte[] DG11) {
    try {
        ASN1InputStream bIn = new ASN1InputStream(DG11);
        org.bouncycastle.asn1.DERApplicationSpecific app = (DERApplicationSpecific) bIn.readObject();

        ASN1Sequence seq = (ASN1Sequence) app.getObject(BERTags.SEQUENCE);
        Enumeration secEnum = seq.getObjects();
        while (secEnum.hasMoreElements()) {
            ASN1Primitive seqObj = (ASN1Primitive) secEnum.nextElement();
            byte[] data = seqObj.getEncoded();
            if (data[0]== 0x7F) {
                parseDG11(data);
            } else if (data[0] == (byte) 0x80) {
                this.setBSN(Arrays.copyOfRange(data, 2, data.length));
            }
        }
        bIn.close();
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
}
 
开发者ID:mDL-ILP,项目名称:mDL-ILP,代码行数:23,代码来源:DrivingLicence.java

示例7: parseCardMappedPublicKey

import org.bouncycastle.asn1.ASN1InputStream; //导入依赖的package包/类
private PublicKey parseCardMappedPublicKey(byte[] data) {

        try (ASN1InputStream innerIn = new ASN1InputStream(Bytes.allButFirst(data, 2))) {
            ASN1Primitive innerObj = innerIn.readObject();
            byte[] innerTLV = innerObj.getEncoded();

            // tag 82 = Mapping Data
            if (innerTLV[0] == (byte) 0x82) {
                // Get the card's Public key
                return ECCUtils.encodeECCPublicKeyX509(Bytes.allButFirst(innerTLV, 2), curveRef);
            }
        } catch (IOException e) {
            Log.e(getClass().getName(), "Failed to parse card public key", e);
        }

        return null;
    }
 
开发者ID:mDL-ILP,项目名称:mDL-ILP,代码行数:18,代码来源:PACEAPDUInterface.java

示例8: parseCardAgreedPublicKey

import org.bouncycastle.asn1.ASN1InputStream; //导入依赖的package包/类
private PublicKey parseCardAgreedPublicKey(byte[] data) {

        try (ASN1InputStream innerIn = new ASN1InputStream(Bytes.allButFirst(data, 2))) {
            ASN1Primitive innerObj = innerIn.readObject();
            byte[] innerTLV = innerObj.getEncoded();

            // tag 82 = Mapping Data
            if (innerTLV[0] == (byte) 0x84) {
                // Get the card's Public key
                return ECCUtils.encodeECCPublicKeyX509(Bytes.allButFirst(innerTLV, 2), curveRef);
            }
        } catch (IOException e) {
            Log.e(getClass().getName(), "Failed to parse card public key", e);
        }

        return null;
    }
 
开发者ID:mDL-ILP,项目名称:mDL-ILP,代码行数:18,代码来源:PACEAPDUInterface.java

示例9: parseAuthCommandResponse

import org.bouncycastle.asn1.ASN1InputStream; //导入依赖的package包/类
private byte[] parseAuthCommandResponse(byte[] data) {

        try (ASN1InputStream innerIn = new ASN1InputStream(Bytes.allButFirst(data, 2))) {
            ASN1Primitive innerObj = innerIn.readObject();
            byte[] innerTLV = innerObj.getEncoded();

            // tag 86 = Mapping Data
            if (innerTLV[0] == (byte) 0x86) {
                // Get the card's Public key
                return Bytes.allButFirst(innerTLV, 2);
            }
        } catch (IOException e) {
            Log.e(getClass().getName(), "Failed to parse card token", e);
        }

        return null;
    }
 
开发者ID:mDL-ILP,项目名称:mDL-ILP,代码行数:18,代码来源:PACEAPDUInterface.java

示例10: parseDG1

import org.bouncycastle.asn1.ASN1InputStream; //导入依赖的package包/类
private void parseDG1(byte[] DG1) {
    try (ASN1InputStream bIn = new ASN1InputStream(DG1)) {

        org.bouncycastle.asn1.DERApplicationSpecific app = (DERApplicationSpecific) bIn.readObject();

        ASN1Sequence seq = (ASN1Sequence) app.getObject(BERTags.SEQUENCE);
        Enumeration secEnum = seq.getObjects();
        while (secEnum.hasMoreElements()) {
            ASN1Primitive seqObj = (ASN1Primitive) secEnum.nextElement();
            byte[] data = seqObj.getEncoded();
            if (data[0]== 0x41) {
                Log.d("type approval number", ByteUtils.bytesToHex(data));
                this.set5F01(Bytes.allButFirst(data, 1));
            } else if (data[0] == 0x42) {
                byte[] input = Arrays.copyOfRange(data, 3, data.length);
                parse5F02(input);
            } else if (data[0] == 0x7F) {
                parse7F63(data);
            }
        }
    } catch (IOException e) {
        Log.e(getClass().getName(), e.getMessage(), e);
    }
}
 
开发者ID:mDL-ILP,项目名称:mDL-ILP,代码行数:25,代码来源:DrivingLicence.java

示例11: parse7F63

import org.bouncycastle.asn1.ASN1InputStream; //导入依赖的package包/类
private void parse7F63(byte[] input) {
    Log.d("input", ByteUtils.bytesToHex(input));
    try (ASN1InputStream bIn = new ASN1InputStream(input)) {
        ASN1Primitive obj = bIn.readObject();
        DERApplicationSpecific app = (DERApplicationSpecific) obj;
        ASN1Sequence seq = (ASN1Sequence) app.getObject(BERTags.SEQUENCE);
        Enumeration secEnum = seq.getObjects();
        List<byte[]> categories = new ArrayList<>();
        while (secEnum.hasMoreElements()) {
            ASN1Primitive seqObj = (ASN1Primitive) secEnum.nextElement();
            byte[] data = seqObj.getEncoded();
            Log.d("5F02data", ByteUtils.bytesToHex(data));
            switch (data[0]) {
                case 0x02:
                    Log.d("#CATEGORY","number of categories:" + data[data.length-1]);
                    break;
                case (byte) 0x87:
                    categories.add(Arrays.copyOfRange(data, 2, data.length));
                    break;
            }
        }
        this.set7F63(categories);
    } catch (IOException e) {
        Log.e(getClass().getName(), e.getMessage(), e);
    }
}
 
开发者ID:mDL-ILP,项目名称:mDL-ILP,代码行数:27,代码来源:DrivingLicence.java

示例12: parseDG11

import org.bouncycastle.asn1.ASN1InputStream; //导入依赖的package包/类
private void parseDG11(byte[] DG11) {
    try (ASN1InputStream bIn = new ASN1InputStream(DG11)) {
        DERApplicationSpecific app = (DERApplicationSpecific) bIn.readObject();

        ASN1Sequence seq = (ASN1Sequence) app.getObject(BERTags.SEQUENCE);
        Enumeration secEnum = seq.getObjects();
        while (secEnum.hasMoreElements()) {
            ASN1Primitive seqObj = (ASN1Primitive) secEnum.nextElement();
            byte[] data = seqObj.getEncoded();
            if (data[0]== 0x7F) {
                parseDG11(data);
            } else if (data[0] == (byte) 0x80) {
                this.setBSN(Arrays.copyOfRange(data, 2, data.length));
            }
        }
    } catch (IOException e) {
        Log.e(getClass().getName(), e.getMessage(), e);
    }
}
 
开发者ID:mDL-ILP,项目名称:mDL-ILP,代码行数:20,代码来源:DrivingLicence.java

示例13: readObject

import org.bouncycastle.asn1.ASN1InputStream; //导入依赖的package包/类
public void readObject(ObjectInputStream in)
    throws IOException, ClassNotFoundException
{
    Object obj = in.readObject();

    if (obj instanceof Hashtable)
    {
        this.pkcs12Attributes = (Hashtable)obj;
        this.pkcs12Ordering = (Vector)in.readObject();
    }
    else
    {
        ASN1InputStream aIn = new ASN1InputStream((byte[])obj);

        DERObjectIdentifier    oid;

        while ((oid = (DERObjectIdentifier)aIn.readObject()) != null)
        {
            this.setBagAttribute(oid, aIn.readObject());
        }
    }
}
 
开发者ID:PhilippC,项目名称:keepass2android,代码行数:23,代码来源:PKCS12BagAttributeCarrierImpl.java

示例14: fromKey

import org.bouncycastle.asn1.ASN1InputStream; //导入依赖的package包/类
private static ASN1Sequence fromKey(
    PublicKey pubKey)
    throws InvalidKeyException
{
    try
    {
        SubjectPublicKeyInfo info = new SubjectPublicKeyInfo(
                                    (ASN1Sequence)new ASN1InputStream(pubKey.getEncoded()).readObject());
    
        return (ASN1Sequence)new AuthorityKeyIdentifier(info).toASN1Object();
    }
    catch (Exception e)
    {
        throw new InvalidKeyException("can't process key: " + e);
    }
}
 
开发者ID:Appdome,项目名称:ipack,代码行数:17,代码来源:AuthorityKeyIdentifierStructure.java

示例15: addCRL

import org.bouncycastle.asn1.ASN1InputStream; //导入依赖的package包/类
/**
 * Add the CRLEntry objects contained in a previous CRL.
 * 
 * @param other the X509CRL to source the other entries from. 
 */
public void addCRL(X509CRL other)
    throws CRLException
{
    Set revocations = other.getRevokedCertificates();

    if (revocations != null)
    {
        Iterator it = revocations.iterator();
        while (it.hasNext())
        {
            X509CRLEntry entry = (X509CRLEntry)it.next();

            ASN1InputStream aIn = new ASN1InputStream(entry.getEncoded());

            try
            {
                tbsGen.addCRLEntry(ASN1Sequence.getInstance(aIn.readObject()));
            }
            catch (IOException e)
            {
                throw new CRLException("exception processing encoding of CRL: " + e.toString());
            }
        }
    }
}
 
开发者ID:Appdome,项目名称:ipack,代码行数:31,代码来源:X509V2CRLGenerator.java


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