本文整理了Java中org.bouncycastle.asn1.ASN1InputStream.close()
方法的一些代码示例,展示了ASN1InputStream.close()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。ASN1InputStream.close()
方法的具体详情如下:
包路径:org.bouncycastle.asn1.ASN1InputStream
类名称:ASN1InputStream
方法名:close
暂无
代码示例来源:origin: stackoverflow.com
ASN1InputStream ais = new ASN1InputStream(
new FileInputStream(new File("d:/myfile.cdr")));
while (ais.available() > 0) {
ASN1Primitive obj = ais.readObject();
System.out.println(ASN1Dump.dumpAsString(obj, true));
}
ais.close();
代码示例来源:origin: be.fedict.commons-eid/commons-eid-consumer
private boolean __verifyNonRepSignature(final byte[] expectedDigestValue, final byte[] signatureValue,
final X509Certificate certificate) throws NoSuchAlgorithmException, NoSuchPaddingException,
InvalidKeyException, IllegalBlockSizeException, BadPaddingException, IOException {
final PublicKey publicKey = certificate.getPublicKey();
final Cipher cipher = Cipher.getInstance("RSA");
cipher.init(Cipher.DECRYPT_MODE, publicKey);
final byte[] actualSignatureDigestInfoValue = cipher.doFinal(signatureValue);
final ASN1InputStream asnInputStream = new ASN1InputStream(actualSignatureDigestInfoValue);
final DigestInfo actualSignatureDigestInfo = new DigestInfo((ASN1Sequence) asnInputStream.readObject());
asnInputStream.close();
final byte[] actualDigestValue = actualSignatureDigestInfo.getDigest();
return Arrays.equals(expectedDigestValue, actualDigestValue);
}
代码示例来源:origin: spoofzu/DeepViolet
/**
* Convert <code>der</code> encoded data to <code>ASN1Primitive</code>.
* For more information,
* (<a href="http://stackoverflow.com/questions/2409618/how-do-i-decode-a-der-encoded-string-in-java">StackOverflow: How do I decode a DER encoded string in Java?</a>)
* @param data byte[] of <code>der</code> encoded data
* @return <code>ASN1Primitive</code> representation of <code>der</code> encoded data
* @throws IOException
*/
static final ASN1Primitive toDERObject(byte[] data) throws IOException {
ByteArrayInputStream inStream = new ByteArrayInputStream(data);
ASN1InputStream asnInputStream = new ASN1InputStream(inStream);
ASN1Primitive p = asnInputStream.readObject();
asnInputStream.close();
return p;
}
代码示例来源:origin: org.demoiselle.signer/policy-engine
private ASN1Primitive readANS1FromStream(InputStream is) {
ASN1InputStream asn1is = new ASN1InputStream(is);
ASN1Primitive primitive = null;
try {
primitive = asn1is.readObject();
} catch (IOException error) {
LOGGER.getLevel();
LOGGER.log(Level.ERROR, "Error reading stream.", error);
throw new RuntimeException(error);
} finally {
try {
asn1is.close();
} catch (IOException error) {
throw new RuntimeException(error);
}
}
return primitive;
}
代码示例来源:origin: org.xipki.scep/scep-server-emulator
protected PKIMessage generatePkiMessage(InputStream is) throws IOException {
ASN1InputStream asn1Stream = new ASN1InputStream(ScepUtil.requireNonNull("is", is));
try {
return PKIMessage.getInstance(asn1Stream.readObject());
} finally {
try {
asn1Stream.close();
} catch (Exception ex) {
LOG.error("could not close stream: {}", ex.getMessage());
}
}
}
代码示例来源:origin: br.gov.frameworkdemoiselle.component/demoiselle-certificate-signer
public enum CertPathEncoding {
PKCS7, PkiPath
}
代码示例来源:origin: org.italiangrid/voms-api-java
private ASN1Encodable getCertAsDEREncodable(X509Certificate cert) {
try {
byte[] certBytes = cert.getEncoded();
ByteArrayInputStream bais = new ByteArrayInputStream(certBytes);
ASN1InputStream is = new ASN1InputStream(bais);
ASN1Object derCert = is.readObject();
is.close();
return derCert;
} catch (CertificateEncodingException e) {
throw new VOMSError("Error encoding X509 certificate: " + e.getMessage(),
e);
} catch (IOException e) {
throw new VOMSError("Error encoding X509 certificate: " + e.getMessage(),
e);
}
}
代码示例来源:origin: sensepost/apostille
private static ASN1Primitive getObject(String oid, byte[] ext) throws AnnotatedException {
try {
ASN1InputStream aIn = new ASN1InputStream(ext);
ASN1OctetString octs = (ASN1OctetString) aIn.readObject();
aIn.close();
aIn = new ASN1InputStream(octs.getOctets());
ASN1Primitive p = aIn.readObject();
aIn.close();
return p;
} catch (Exception e) {
throw new AnnotatedException("exception processing extension " + oid, e);
}
}
代码示例来源:origin: org.apache.camel/camel-asn1
@Override
public boolean hasNext() {
try {
if (asn1InputStream == null) {
return false;
}
boolean availableDataInCurrentEntry = asn1InputStream.available() > 0;
if (!availableDataInCurrentEntry) {
// advance to the next entry.
parent = getNextElement();
if (parent == null) {
asn1InputStream.close();
availableDataInCurrentEntry = false;
} else {
availableDataInCurrentEntry = true;
}
}
return availableDataInCurrentEntry;
} catch (IOException exception) {
//Just wrap the IOException as CamelRuntimeException
throw new RuntimeCamelException(exception);
}
}
代码示例来源:origin: org.apache.camel/camel-asn1
@Override
public boolean hasNext() {
try {
if (asn1InputStream == null) {
return false;
}
boolean availableDataInCurrentEntry = asn1InputStream.available() > 0;
if (!availableDataInCurrentEntry) {
// advance to the next entry.
parent = getNextElement();
if (parent == null) {
asn1InputStream.close();
availableDataInCurrentEntry = false;
} else {
availableDataInCurrentEntry = true;
}
}
return availableDataInCurrentEntry;
} catch (IOException exception) {
// Just wrap the IOException as CamelRuntimeException
throw new RuntimeCamelException(exception);
}
}
代码示例来源:origin: eu.eu-emi.security/canl
private void establishKeys(ProxyCertificateOptions param) throws InvalidKeyException
{
PublicKey proxyPublicKey = param.getPublicKey();
proxyPrivateKey = null;
if (proxyPublicKey == null)
{
KeyPair pair = ProxyGeneratorHelper.generateKeyPair(param.getKeyLength());
proxyPublicKey = pair.getPublic();
proxyPrivateKey = pair.getPrivate();
}
try
{
ASN1InputStream asn1IS = new ASN1InputStream(proxyPublicKey.getEncoded());
proxyPublicKeyInfo = SubjectPublicKeyInfo.getInstance(asn1IS.readObject());
asn1IS.close();
} catch (IOException e)
{
throw new InvalidKeyException("Can not parse the public key" +
"being included in the proxy certificate", e);
}
}
代码示例来源:origin: CryptoKass/dilithium
public static ECDSASignature decodeFromDER(byte[] bytes) {
ASN1InputStream decoder = null;
try {
decoder = new ASN1InputStream(bytes);
DLSequence seq = (DLSequence) decoder.readObject();
if (seq == null)
throw new RuntimeException("Reached past end of ASN.1 stream.");
ASN1Integer r, s;
try {
r = (ASN1Integer) seq.getObjectAt(0);
s = (ASN1Integer) seq.getObjectAt(1);
} catch (ClassCastException e) {
throw new IllegalArgumentException(e);
}
// OpenSSL deviates from the DER spec by interpreting these values as unsigned, though they should not be
// Thus, we always use the positive versions. See: http://r6.ca/blog/20111119T211504Z.html
return new ECDSASignature(r.getPositiveValue(), s.getPositiveValue());
} catch (IOException e) {
throw new RuntimeException(e);
} finally {
if (decoder != null)
try { decoder.close(); } catch (IOException x) {}
}
}
代码示例来源:origin: org.italiangrid/voms-api-java
/**
* Extracts an AC from a VOMS response
*
* @param request
* the request
* @param response
* the received response
* @return a possibly <code>null</code> {@link AttributeCertificate} object
*/
protected AttributeCertificate getACFromResponse(VOMSACRequest request,
VOMSResponse response) {
byte[] acBytes = response.getAC();
if (acBytes == null)
return null;
ASN1InputStream asn1InputStream = new ASN1InputStream(acBytes);
AttributeCertificate attributeCertificate = null;
try {
attributeCertificate = AttributeCertificate.getInstance(asn1InputStream
.readObject());
asn1InputStream.close();
return attributeCertificate;
} catch (Throwable e) {
requestListener.notifyVOMSRequestFailure(request, null, new VOMSError(
"Error unmarshalling VOMS AC. Cause: " + e.getMessage(), e));
return null;
}
}
代码示例来源:origin: stackoverflow.com
import java.io.IOException;
import java.math.BigInteger;
import org.bouncycastle.asn1.ASN1EncodableVector;
import org.bouncycastle.asn1.ASN1InputStream;
import org.bouncycastle.asn1.ASN1Integer;
import org.bouncycastle.asn1.DERSequence;
import org.bouncycastle.asn1.DLSequence;
public class RsaAsn1Example {
// ...
public static BigInteger [] parseASN1RsaPublicKey(byte [] encoded) throws IOException {
ASN1InputStream asn1_is = new ASN1InputStream(encoded);
DLSequence dlSeq = (DLSequence) asn1_is.readObject();
ASN1Integer asn1_n = (ASN1Integer) dlSeq.getObjectAt(0);
ASN1Integer asn1_e = (ASN1Integer) dlSeq.getObjectAt(1);
asn1_is.close();
return new BigInteger[]{ asn1_n.getPositiveValue(), asn1_e.getPositiveValue()};
}
// ....
}
代码示例来源:origin: BMF-RKSV-Technik/at-registrierkassen-mustercode
/**
* Helper method to convert DER-encoded signature values (e.g. used by Java)
* to concatenated signature values
* (as used by the JWS-standard)
*
* @param derEncodedSignatureValue
* DER-encoded signature value
* @return concatenated signature value (as used by JWS standard)
* @throws IOException
*/
public static byte[] convertDEREncodedSignatureToJWSConcatenated(final byte[] derEncodedSignatureValue)
throws IOException {
final ASN1InputStream asn1InputStream = new ASN1InputStream(derEncodedSignatureValue);
final ASN1Primitive asn1Primitive = asn1InputStream.readObject();
asn1InputStream.close();
final ASN1Sequence asn1Sequence = (ASN1Sequence.getInstance(asn1Primitive));
final ASN1Integer rASN1 = (ASN1Integer) asn1Sequence.getObjectAt(0);
final ASN1Integer sASN1 = (ASN1Integer) asn1Sequence.getObjectAt(1);
final X9IntegerConverter x9IntegerConverter = new X9IntegerConverter();
final byte[] r = x9IntegerConverter.integerToBytes(rASN1.getValue(), 32);
final byte[] s = x9IntegerConverter.integerToBytes(sASN1.getValue(), 32);
final byte[] concatenatedSignatureValue = new byte[64];
System.arraycopy(r, 0, concatenatedSignatureValue, 0, 32);
System.arraycopy(s, 0, concatenatedSignatureValue, 32, 32);
return concatenatedSignatureValue;
}
代码示例来源:origin: eBay/UAF
/**
* 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;
}
代码示例来源:origin: eBay/UAF
/**
* 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;
}
代码示例来源:origin: arhs/sd-dss
/**
* This method returns the {@code ASN1Sequence} encapsulated in {@code DEROctetString}. The {@code DEROctetString} is represented as {@code byte} array.
*
* @param bytes {@code byte} representation of {@code DEROctetString}
* @return encapsulated {@code ASN1Sequence}
* @throws DSSException in case of a decoding problem
*/
public static ASN1Sequence getAsn1SequenceFromDerOctetString(byte[] bytes) throws DSSException {
ASN1InputStream input = null;
try {
input = new ASN1InputStream(bytes);
final DEROctetString s = (DEROctetString) input.readObject();
final byte[] content = s.getOctets();
input.close();
input = new ASN1InputStream(content);
final ASN1Sequence seq = (ASN1Sequence) input.readObject();
return seq;
} catch (IOException e) {
throw new DSSException("Error when converting byte array to ASN1Sequence!", e);
} finally {
DSSUtils.closeQuietly(input);
}
}
代码示例来源:origin: com.amazon.device.tools.build/builder
asn1.close();
代码示例来源:origin: hyperledger-archives/fabric-api
@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) {
}
}
}
内容来源于网络,如有侵权,请联系作者删除!