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


Java ASN1StreamParser类代码示例

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


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

示例1: testMalleableSignature

import org.bouncycastle.asn1.ASN1StreamParser; //导入依赖的package包/类
@Test
public void testMalleableSignature() throws Exception {
    for (int i = 0; i < 1000; i++) {
        PrivateKey key = PrivateKey.createNew(true);

        byte[] signature = key.sign(MESSAGE.getBytes());

        ASN1StreamParser asn1 = new ASN1StreamParser(signature);

        DERSequence seq = (DERSequence) asn1.readObject().toASN1Primitive();
        BigInteger s = ((ASN1Integer) seq.getObjectAt(1)).getPositiveValue();

        assertTrue(key.getPublic().verify(MESSAGE.getBytes(), signature));
        assertTrue(String.format("Signature is not canonical for iteration %d key %s", i, key), isCanonical(s));
    }
}
 
开发者ID:DigitalAssetCom,项目名称:-deprecated-hlp-candidate,代码行数:17,代码来源:ECKeyPairTest.java

示例2: parserTest

import org.bouncycastle.asn1.ASN1StreamParser; //导入依赖的package包/类
private void parserTest()
{
    for (int i = 0; i != streams.length; i++)
    {
        ASN1StreamParser aIn = new ASN1StreamParser(Base64.decode(streams[i]));

        try
        {
            Object obj;

            while ((obj = aIn.readObject()) != null)
            {

            }

            fail("bad stream parsed successfully!");
        }
        catch (IOException e)
        {
            // ignore
        }
    }
}
 
开发者ID:ttt43ttt,项目名称:gwt-crypto,代码行数:24,代码来源:ParsingTest.java

示例3: performTest

import org.bouncycastle.asn1.ASN1StreamParser; //导入依赖的package包/类
public void performTest()
    throws Exception
{
    testPKCS12Store();
    testGOSTStore();

    // converter tests

    KeyStore kS = KeyStore.getInstance("PKCS12", "BC");

    byte[] data = PKCS12Util.convertToDefiniteLength(pkcs12);
    kS.load(new ByteArrayInputStream(data), passwd);     // check MAC

    ASN1Encodable obj = new ASN1StreamParser(data).readObject();
    if (!(obj instanceof DERSequenceParser))
    {
        fail("Failed DER conversion test.");
    }

    data = PKCS12Util.convertToDefiniteLength(pkcs12, passwd, "BC");
    kS.load(new ByteArrayInputStream(data), passwd); //check MAC

    obj = new ASN1StreamParser(data).readObject();
    if (!(obj instanceof DERSequenceParser))
    {
        fail("Failed deep DER conversion test - outer.");
    }

    Pfx pfx = Pfx.getInstance(obj);

    obj = new ASN1StreamParser(ASN1OctetString.getInstance(pfx.getAuthSafe().getContent()).getOctets()).readObject();
    if (!(obj instanceof DERSequenceParser))
    {
        fail("Failed deep DER conversion test - inner.");
    }
}
 
开发者ID:NoYouShutup,项目名称:CryptMeme,代码行数:37,代码来源:PKCS12StoreTest.java

示例4: readAsn1Encodable

import org.bouncycastle.asn1.ASN1StreamParser; //导入依赖的package包/类
private static ASN1Encodable readAsn1Encodable(byte[] encoded) throws CertprofileException {
    ASN1StreamParser parser = new ASN1StreamParser(encoded);
    try {
        return parser.readObject();
    } catch (IOException ex) {
        throw new CertprofileException("could not parse the constant extension value", ex);
    }
}
 
开发者ID:xipki,项目名称:xipki,代码行数:9,代码来源:XmlX509Certprofile.java

示例5: buildConstantExtesions

import org.bouncycastle.asn1.ASN1StreamParser; //导入依赖的package包/类
public static Map<ASN1ObjectIdentifier, ExtensionValue> buildConstantExtesions(
        ExtensionsType extensionsType) throws CertprofileException {
    if (extensionsType == null) {
        return null;
    }

    Map<ASN1ObjectIdentifier, ExtensionValue> map = new HashMap<>();

    for (ExtensionType m : extensionsType.getExtension()) {
        ASN1ObjectIdentifier oid = new ASN1ObjectIdentifier(m.getType().getValue());
        if (Extension.subjectAlternativeName.equals(oid)
                || Extension.subjectInfoAccess.equals(oid)
                || Extension.biometricInfo.equals(oid)) {
            continue;
        }

        if (m.getValue() == null || !(m.getValue().getAny() instanceof ConstantExtValue)) {
            continue;
        }

        ConstantExtValue extConf = (ConstantExtValue) m.getValue().getAny();
        byte[] encodedValue = extConf.getValue();
        ASN1StreamParser parser = new ASN1StreamParser(encodedValue);
        ASN1Encodable value;
        try {
            value = parser.readObject();
        } catch (IOException ex) {
            throw new CertprofileException("could not parse the constant extension value", ex);
        }
        ExtensionValue extension = new ExtensionValue(m.isCritical(), value);
        map.put(oid, extension);
    }

    if (CollectionUtil.isEmpty(map)) {
        return null;
    }

    return Collections.unmodifiableMap(map);
}
 
开发者ID:xipki,项目名称:xipki,代码行数:40,代码来源:XmlX509CertprofileUtil.java

示例6: buildConstantExtesions

import org.bouncycastle.asn1.ASN1StreamParser; //导入依赖的package包/类
public static Map<ASN1ObjectIdentifier, QaExtensionValue> buildConstantExtesions(
        ExtensionsType extensionsType) throws CertprofileException {
    if (extensionsType == null) {
        return null;
    }

    Map<ASN1ObjectIdentifier, QaExtensionValue> map = new HashMap<>();

    for (ExtensionType m : extensionsType.getExtension()) {
        if (m.getValue() == null || !(m.getValue().getAny() instanceof ConstantExtValue)) {
            continue;
        }

        ASN1ObjectIdentifier oid = new ASN1ObjectIdentifier(m.getType().getValue());
        if (Extension.subjectAlternativeName.equals(oid)
                || Extension.subjectInfoAccess.equals(oid)
                || Extension.biometricInfo.equals(oid)) {
            continue;
        }

        ConstantExtValue extConf = (ConstantExtValue) m.getValue().getAny();
        byte[] encodedValue = extConf.getValue();
        ASN1StreamParser parser = new ASN1StreamParser(encodedValue);
        try {
            parser.readObject();
        } catch (IOException ex) {
            throw new CertprofileException("could not parse the constant extension value", ex);
        }
        QaExtensionValue extension = new QaExtensionValue(m.isCritical(), encodedValue);
        map.put(oid, extension);
    }

    if (CollectionUtil.isEmpty(map)) {
        return null;
    }

    return Collections.unmodifiableMap(map);
}
 
开发者ID:xipki,项目名称:xipki,代码行数:39,代码来源:ExtensionsChecker.java

示例7: testLongTag

import org.bouncycastle.asn1.ASN1StreamParser; //导入依赖的package包/类
public void testLongTag()
    throws IOException
{
    ASN1StreamParser aIn = new ASN1StreamParser(longTagged);
    
    ASN1TaggedObjectParser tagged = (ASN1TaggedObjectParser)aIn.readObject();
    
    assertEquals(31, tagged.getTagNo());
}
 
开发者ID:credentials,项目名称:irma_future_id,代码行数:10,代码来源:ParseTest.java

示例8: testDERReading

import org.bouncycastle.asn1.ASN1StreamParser; //导入依赖的package包/类
public void testDERReading()
    throws Exception
{
    ASN1StreamParser aIn = new ASN1StreamParser(seqData);
    
    ASN1SequenceParser    seq = (ASN1SequenceParser)aIn.readObject();
    Object          o;
    int             count = 0;
    
    assertNotNull("null sequence returned", seq);
    
    while ((o = seq.readObject()) != null)
    {
        switch (count)
        {
        case 0:
            assertTrue(o instanceof DERInteger);
            break;
        case 1:
            assertTrue(o instanceof DERObjectIdentifier);
            break;
        }
        count++;
    }
    
    assertEquals("wrong number of objects in sequence", 2, count);
}
 
开发者ID:credentials,项目名称:irma_future_id,代码行数:28,代码来源:ASN1SequenceParserTest.java

示例9: testNestedReading

import org.bouncycastle.asn1.ASN1StreamParser; //导入依赖的package包/类
private void testNestedReading(
    byte[] data)
    throws Exception
{
    ASN1StreamParser aIn = new ASN1StreamParser(data);
    
    ASN1SequenceParser seq = (ASN1SequenceParser)aIn.readObject();
    Object          o;
    int             count = 0;
    
    assertNotNull("null sequence returned", seq);
    
    while ((o = seq.readObject()) != null)
    {
        switch (count)
        {
        case 0:
            assertTrue(o instanceof DERInteger);
            break;
        case 1:
            assertTrue(o instanceof DERObjectIdentifier);
            break;
        case 2:
            assertTrue(o instanceof ASN1SequenceParser);
            
            ASN1SequenceParser s = (ASN1SequenceParser)o;

            // NB: Must exhaust the nested parser
            while (s.readObject() != null)
            {
                // Nothing
            }

            break;
        }
        count++;
    }
    
    assertEquals("wrong number of objects in sequence", 3, count);
}
 
开发者ID:credentials,项目名称:irma_future_id,代码行数:41,代码来源:ASN1SequenceParserTest.java

示例10: testBERReading

import org.bouncycastle.asn1.ASN1StreamParser; //导入依赖的package包/类
public void testBERReading()
    throws Exception
{
    ASN1StreamParser aIn = new ASN1StreamParser(berSeqData);
    
    ASN1SequenceParser    seq = (ASN1SequenceParser)aIn.readObject();
    Object          o;
    int             count = 0;
    
    assertNotNull("null sequence returned", seq);
    
    while ((o = seq.readObject()) != null)
    {
        switch (count)
        {
        case 0:
            assertTrue(o instanceof DERInteger);
            break;
        case 1:
            assertTrue(o instanceof DERObjectIdentifier);
            break;
        }
        count++;
    }
    
    assertEquals("wrong number of objects in sequence", 2, count);
}
 
开发者ID:credentials,项目名称:irma_future_id,代码行数:28,代码来源:ASN1SequenceParserTest.java

示例11: testParseWithNull

import org.bouncycastle.asn1.ASN1StreamParser; //导入依赖的package包/类
private void testParseWithNull(byte[] data)
    throws IOException
{
    ASN1StreamParser aIn = new ASN1StreamParser(data);
    ASN1SequenceParser seq = (ASN1SequenceParser)aIn.readObject();
    Object          o;
    int             count = 0;

    assertNotNull("null sequence returned", seq);

    while ((o = seq.readObject()) != null)
    {
        switch (count)
        {
        case 0:
            assertTrue(o instanceof ASN1Null);
            break;
        case 1:
            assertTrue(o instanceof DERInteger);
            break;
        case 2:
            assertTrue(o instanceof DERObjectIdentifier);
            break;
        }
        count++;
    }

    assertEquals("wrong number of objects in sequence", 3, count);
}
 
开发者ID:credentials,项目名称:irma_future_id,代码行数:30,代码来源:ASN1SequenceParserTest.java

示例12: testReadingWriting

import org.bouncycastle.asn1.ASN1StreamParser; //导入依赖的package包/类
public void testReadingWriting()
    throws Exception
{
   ByteArrayOutputStream bOut = new ByteArrayOutputStream();
   BEROctetStringGenerator octGen = new BEROctetStringGenerator(bOut);
   
   OutputStream out = octGen.getOctetOutputStream();
   
   out.write(new byte[] { 1, 2, 3, 4 });
   out.write(new byte[4]);
   
   out.close();
   
   ASN1StreamParser aIn = new ASN1StreamParser(bOut.toByteArray());
   
   ASN1OctetStringParser s = (ASN1OctetStringParser)aIn.readObject();
   
   InputStream in = s.getOctetStream();
   int         count = 0;
   
   while (in.read() >= 0)
   {
       count++;
   }

   assertEquals(8, count);
}
 
开发者ID:credentials,项目名称:irma_future_id,代码行数:28,代码来源:OctetStringTest.java

示例13: testReadingWritingZeroInLength

import org.bouncycastle.asn1.ASN1StreamParser; //导入依赖的package包/类
public void testReadingWritingZeroInLength()
    throws Exception
{
   ByteArrayOutputStream bOut = new ByteArrayOutputStream();
   BEROctetStringGenerator octGen = new BEROctetStringGenerator(bOut);
   
   OutputStream out = octGen.getOctetOutputStream();
   
   out.write(new byte[] { 1, 2, 3, 4 });
   out.write(new byte[512]);  // forces a zero to appear in length
   
   out.close();
   
   ASN1StreamParser aIn = new ASN1StreamParser(bOut.toByteArray());
   
   ASN1OctetStringParser s = (ASN1OctetStringParser)aIn.readObject();
   
   InputStream in = s.getOctetStream();
   int         count = 0;
   
   while (in.read() >= 0)
   {
       count++;
   }

   assertEquals(516, count);
}
 
开发者ID:credentials,项目名称:irma_future_id,代码行数:28,代码来源:OctetStringTest.java

示例14: CVCertificate

import org.bouncycastle.asn1.ASN1StreamParser; //导入依赖的package包/类
public CVCertificate(byte[] in) throws IllegalArgumentException, IOException {
	ASN1StreamParser asn1Parser = new ASN1StreamParser(in);
	
	DERApplicationSpecific cvcert = (DERApplicationSpecific) asn1Parser.readObject();
	if (cvcert.getApplicationTag()!=0x21) throw new IllegalArgumentException("Can't find a CV Certificate");
	
	ASN1Sequence derCert= (ASN1Sequence)cvcert.getObject(BERTags.SEQUENCE); // Das CV Cerificate ist eine Sequence
	
	DERApplicationSpecific body = (DERApplicationSpecific) derCert.getObjectAt(0); //Das erste Objekt des Certificates ist der Cert-Body
	if (body.getApplicationTag()!=0x4E) throw new IllegalArgumentException("Can't find a Body in the CV Certificate");
	
	certBody = new CVCertBody(body);
	
	DERApplicationSpecific signature = (DERApplicationSpecific) derCert.getObjectAt(1); //Das zweite Objekt des Certificates ist die Signatur
	if (signature.getApplicationTag()!=0x37) throw new IllegalArgumentException("Can't find a Signature in the CV Certificate");

	certSignature = new CVCertSignature(signature.getContents());
	
}
 
开发者ID:tsenger,项目名称:animamea,代码行数:20,代码来源:CVCertificate.java

示例15: parseEnveloped

import org.bouncycastle.asn1.ASN1StreamParser; //导入依赖的package包/类
private void parseEnveloped(byte[] data) throws IOException
{
    ASN1StreamParser aIn = new ASN1StreamParser(data);
    
    ContentInfoParser cP = new ContentInfoParser((ASN1SequenceParser)aIn.readObject());
    
    EnvelopedDataParser eP = new EnvelopedDataParser((ASN1SequenceParser)cP.getContent(BERTags.SEQUENCE));
    
    eP.getRecipientInfos().toASN1Primitive(); // Must drain the parser!
    
    EncryptedContentInfoParser ecP = eP.getEncryptedContentInfo();
    
    ASN1OctetStringParser content = (ASN1OctetStringParser)ecP.getEncryptedContent(BERTags.OCTET_STRING);

    Streams.drain(content.getOctetStream());
}
 
开发者ID:credentials,项目名称:irma_future_id,代码行数:17,代码来源:ParseTest.java


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