本文整理汇总了Java中org.bouncycastle.asn1.ASN1InputStream.close方法的典型用法代码示例。如果您正苦于以下问题:Java ASN1InputStream.close方法的具体用法?Java ASN1InputStream.close怎么用?Java ASN1InputStream.close使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.bouncycastle.asn1.ASN1InputStream
的用法示例。
在下文中一共展示了ASN1InputStream.close方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: verify
import org.bouncycastle.asn1.ASN1InputStream; //导入方法依赖的package包/类
@Override
public boolean verify(byte[] hash, byte[] signature, byte[] publicKey) {
ASN1InputStream asn1 = new ASN1InputStream(signature);
try {
ECDSASigner signer = new ECDSASigner();
signer.init(false, new ECPublicKeyParameters(curve.getCurve().decodePoint(publicKey), domain));
DLSequence seq = (DLSequence) asn1.readObject();
BigInteger r = ((ASN1Integer) seq.getObjectAt(0)).getPositiveValue();
BigInteger s = ((ASN1Integer) seq.getObjectAt(1)).getPositiveValue();
return signer.verifySignature(hash, r, s);
} catch (Exception e) {
return false;
} finally {
try {
asn1.close();
} catch (IOException ignored) {
}
}
}
示例2: 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();
}
}
示例3: 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();
}
}
示例4: 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;
}
}
bIn.close();
this.set7F63(categories);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
示例5: writeSignatureBlock
import org.bouncycastle.asn1.ASN1InputStream; //导入方法依赖的package包/类
/**
* Write the certificate file with a digital signature.
*/
private void writeSignatureBlock(CMSTypedData data,
X509Certificate publicKey,
PrivateKey privateKey) throws IOException, CertificateEncodingException, OperatorCreationException, CMSException {
ArrayList<X509Certificate> certList = new ArrayList<X509Certificate>();
certList.add(publicKey);
JcaCertStore certs = new JcaCertStore(certList);
CMSSignedDataGenerator gen = new CMSSignedDataGenerator();
ContentSigner sha1Signer = new JcaContentSignerBuilder("SHA1with" +
privateKey.getAlgorithm()).build(
privateKey);
gen.addSignerInfoGenerator(new JcaSignerInfoGeneratorBuilder(new JcaDigestCalculatorProviderBuilder()
.build()).setDirectSignature(
true).build(sha1Signer, publicKey));
gen.addCertificates(certs);
CMSSignedData sigData = gen.generate(data, false);
ASN1InputStream asn1 = new ASN1InputStream(sigData.getEncoded());
DEROutputStream dos = new DEROutputStream(mOutputJar);
dos.writeObject(asn1.readObject());
dos.flush();
dos.close();
asn1.close();
}
示例6: decodeToBigIntegerArray
import org.bouncycastle.asn1.ASN1InputStream; //导入方法依赖的package包/类
/**
* DER - From byte[] to Big Integer rs
* UAF_ALG_SIGN_SECP256K1_ECDSA_SHA256_DER 0x06 DER [ITU-X690-2008] encoded
* ECDSA signature [RFC5480] on the secp256k1 curve. I.e. a DER encoded
* SEQUENCE { r INTEGER, s INTEGER }
*
* @param signature
* @return
* @throws IOException
*/
public static BigInteger[] decodeToBigIntegerArray(byte[] signature)
throws IOException {
ASN1InputStream decoder = new ASN1InputStream(signature);
DLSequence seq = (DLSequence) decoder.readObject();
ASN1Integer r = (ASN1Integer) seq.getObjectAt(0);
ASN1Integer s = (ASN1Integer) seq.getObjectAt(1);
decoder.close();
BigInteger[] ret = new BigInteger[2];
ret[0] = r.getPositiveValue();
ret[1] = s.getPositiveValue();
return ret;
}
示例7: KerberosRelevantAuthData
import org.bouncycastle.asn1.ASN1InputStream; //导入方法依赖的package包/类
public KerberosRelevantAuthData(byte[] token, Key key) throws DecodingException {
// System.out.println(HexDump.xdump(token));
// dk.appliedcrypto.spnego.Pac pac;
// try {
// pac = new dk.appliedcrypto.spnego.Pac(new DerInputStream(token));
// authdata = pac.getLogonInfo();
// } catch (IOException e1) {
// throw new DecodingException();
// // TODO Auto-generated catch block
//// e1.printStackTrace();
// }
ASN1InputStream stream = new ASN1InputStream(new ByteArrayInputStream(token));
ASN1Sequence authSequence;
try {
authSequence = DecodingUtil.as(ASN1Sequence.class, stream);
stream.close();
} catch(IOException e) {
throw new DecodingException("kerberos.ticket.malformed", null, e);
}
authorizations = new ArrayList<KerberosAuthData>();
Enumeration<?> authElements = authSequence.getObjects();
while(authElements.hasMoreElements()) {
ASN1Sequence authElement = DecodingUtil.as(ASN1Sequence.class, authElements);
ASN1Integer authType = DecodingUtil.as(ASN1Integer.class, DecodingUtil.as(
DERTaggedObject.class, authElement, 0));
DEROctetString authData = DecodingUtil.as(DEROctetString.class, DecodingUtil.as(
DERTaggedObject.class, authElement, 1));
authorizations.addAll(KerberosAuthData.parse(authType.getValue().intValue(), authData
.getOctets(), key));
}
}
示例8: writeSignatureBlock
import org.bouncycastle.asn1.ASN1InputStream; //导入方法依赖的package包/类
/** Write the certificate file with a digital signature. */
private void writeSignatureBlock(CMSTypedData data, X509Certificate publicKey,
PrivateKey privateKey)
throws IOException,
CertificateEncodingException,
OperatorCreationException,
CMSException {
ArrayList<X509Certificate> certList = new ArrayList<X509Certificate>();
certList.add(publicKey);
JcaCertStore certs = new JcaCertStore(certList);
CMSSignedDataGenerator gen = new CMSSignedDataGenerator();
ContentSigner sha1Signer = new JcaContentSignerBuilder(
"SHA1with" + privateKey.getAlgorithm())
.build(privateKey);
gen.addSignerInfoGenerator(
new JcaSignerInfoGeneratorBuilder(
new JcaDigestCalculatorProviderBuilder()
.build())
.setDirectSignature(true)
.build(sha1Signer, publicKey));
gen.addCertificates(certs);
CMSSignedData sigData = gen.generate(data, false);
ASN1InputStream asn1 = new ASN1InputStream(sigData.getEncoded());
DEROutputStream dos = new DEROutputStream(mOutputJar);
dos.writeObject(asn1.readObject());
dos.flush();
dos.close();
asn1.close();
}
示例9: parse5F02
import org.bouncycastle.asn1.ASN1InputStream; //导入方法依赖的package包/类
private void parse5F02(byte[] input) {
Log.d("input", ByteUtils.bytesToHex(input));
try {
ASN1InputStream bIn = new ASN1InputStream(input);
ASN1Primitive obj;
while ((obj = bIn.readObject())!= null) {
byte[] data = obj.getEncoded();
Log.d("5F02data", ByteUtils.bytesToHex(data));
switch (data[0]) {
case 0x43:
this.set5F03(Arrays.copyOfRange(data, 2, data.length));
break;
case 0x44:
this.set5F04(Arrays.copyOfRange(data, 2, data.length));
break;
case 0x45:
this.set5F05(Arrays.copyOfRange(data, 2, data.length));
break;
case 0x46:
this.set5F06(Arrays.copyOfRange(data, 2, data.length));
break;
case 0x47:
this.set5F07(Arrays.copyOfRange(data, 2, data.length));
break;
case 0x48:
this.set5F08(Arrays.copyOfRange(data, 2, data.length));
break;
case 0x49:
this.set5F09(Arrays.copyOfRange(data, 2, data.length));
break;
case 0x4A:
this.set5F0A(Arrays.copyOfRange(data, 2, data.length));
break;
case 0x4B:
this.set5F0B(Arrays.copyOfRange(data, 2, data.length));
break;
case 0x4C:
this.set5F0C(Arrays.copyOfRange(data, 2, data.length));
break;
case 0x4E:
this.set5F0E(Arrays.copyOfRange(data, 2, data.length));
break;
case 0x4F:
this.set5F0F(Arrays.copyOfRange(data, 2, data.length));
break;
default:
Log.d("UNKNOWN_TAG", "unknown tag");
}
bIn.close();
}
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}