本文整理汇总了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));
}
}
示例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
}
}
}
示例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.");
}
}
示例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);
}
}
示例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);
}
示例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);
}
示例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());
}
示例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);
}
示例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);
}
示例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);
}
示例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);
}
示例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);
}
示例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);
}
示例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());
}
示例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());
}