本文整理了Java中org.bouncycastle.asn1.DLSequence.getObjectAt()
方法的一些代码示例,展示了DLSequence.getObjectAt()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。DLSequence.getObjectAt()
方法的具体详情如下:
包路径:org.bouncycastle.asn1.DLSequence
类名称:DLSequence
方法名:getObjectAt
暂无
代码示例来源:origin: apache/pdfbox
DERTaggedObject derTagged = (DERTaggedObject) obj.getObjectAt(0);
derTagged = (DERTaggedObject) derTagged.getObject();
derTagged = (DERTaggedObject) derTagged.getObject();
代码示例来源:origin: org.apache.ratis/ratis-proto-shaded
private static <T> T findObject(DLSequence sequence, ASN1ObjectIdentifier oid, Class<T> type) {
for (ASN1Encodable element : sequence) {
if (!(element instanceof DLSequence)) {
continue;
}
DLSequence subSequence = (DLSequence) element;
if (subSequence.size() != 2) {
continue;
}
ASN1Encodable key = subSequence.getObjectAt(0);
ASN1Encodable value = subSequence.getObjectAt(1);
if (key.equals(oid) && type.isInstance(value)) {
return type.cast(value);
}
}
return null;
}
代码示例来源:origin: AgNO3/jcifs-ng
/**
*
* @param type
* @param sequence
* @param index
* @return sequence element cast to type
* @throws PACDecodingException
*/
public static <T extends ASN1Primitive> T as ( Class<T> type, DLSequence sequence, int index ) throws PACDecodingException {
return as(type, sequence.getObjectAt(index));
}
代码示例来源:origin: org.codelibs/jcifs
/**
*
* @param type
* @param sequence
* @param index
* @return sequence element cast to type
* @throws PACDecodingException
*/
public static <T extends ASN1Primitive> T as ( Class<T> type, DLSequence sequence, int index ) throws PACDecodingException {
return as(type, sequence.getObjectAt(index));
}
代码示例来源:origin: eu.eu-emi.security/canl
/**
* Used to get the AC extension object.
*
* @return The AC object
*/
public AttributeCertificate[] getAttributeCertificates()
{
DLSequence seqac = (DLSequence) ac.getObjectAt(0);
AttributeCertificate[] ret = new AttributeCertificate[seqac.size()];
for (int i=0; i<ret.length; i++)
ret[i] = AttributeCertificate.getInstance(seqac.getObjectAt(i));
return ret;
}
代码示例来源:origin: org.demoiselle.signer/policy-engine
@Override
public void parse(ASN1Primitive derObject) {
this.algorithm = new ObjectIdentifier();
DLSequence derSequence = (DLSequence) derObject;
this.algorithm.parse(derSequence.getObjectAt(0).toASN1Primitive());
}
代码示例来源:origin: iNPUTmice/ComplianceTester
private static OtherName parseOtherName(byte[] otherName) {
try {
ASN1Primitive asn1Primitive = ASN1Primitive.fromByteArray(otherName);
if (asn1Primitive instanceof DERTaggedObject) {
ASN1Primitive inner = ((DERTaggedObject) asn1Primitive).getObject();
if (inner instanceof DLSequence) {
DLSequence sequence = (DLSequence) inner;
if (sequence.size() >= 2 && sequence.getObjectAt(1) instanceof DERTaggedObject) {
String oid = sequence.getObjectAt(0).toString();
ASN1Primitive value = ((DERTaggedObject) sequence.getObjectAt(1)).getObject();
if (value instanceof DERUTF8String) {
return new OtherName(oid, ((DERUTF8String) value).getString());
} else if (value instanceof DERIA5String) {
return new OtherName(oid, ((DERIA5String) value).getString());
}
}
}
}
return null;
} catch (IOException e) {
return null;
}
}
代码示例来源: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: 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: iNPUTmice/caas
private static OtherName parseOtherName(byte[] otherName) {
try {
ASN1Primitive asn1Primitive = ASN1Primitive.fromByteArray(otherName);
if (asn1Primitive instanceof DERTaggedObject) {
ASN1Primitive inner = ((DERTaggedObject) asn1Primitive).getObject();
if (inner instanceof DLSequence) {
DLSequence sequence = (DLSequence) inner;
if (sequence.size() >= 2 && sequence.getObjectAt(1) instanceof DERTaggedObject) {
String oid = sequence.getObjectAt(0).toString();
ASN1Primitive value = ((DERTaggedObject) sequence.getObjectAt(1)).getObject();
if (value instanceof DERUTF8String) {
return new OtherName(oid, ((DERUTF8String) value).getString());
} else if (value instanceof DERIA5String) {
return new OtherName(oid, ((DERIA5String) value).getString());
}
}
}
}
return null;
} catch (IOException e) {
return null;
}
}
代码示例来源:origin: esig/dss
public static byte[] computeSkiFromCert(final CertificateToken certificateToken) {
try {
DLSequence seq = (DLSequence) DERSequence.fromByteArray(certificateToken.getPublicKey().getEncoded());
DERBitString item = (DERBitString) seq.getObjectAt(1);
return DSSUtils.digest(DigestAlgorithm.SHA1, item.getOctets());
} catch (IOException e) {
throw new DSSException(e);
}
}
代码示例来源:origin: arhs/sd-dss
private static HashMap<String, String> get(final X500Principal x500Principal) {
HashMap<String, String> treeMap = new HashMap<String, String>();
final byte[] encoded = x500Principal.getEncoded();
final ASN1Sequence asn1Sequence = ASN1Sequence.getInstance(encoded);
final ASN1Encodable[] asn1Encodables = asn1Sequence.toArray();
for (final ASN1Encodable asn1Encodable : asn1Encodables) {
final DLSet dlSet = (DLSet) asn1Encodable;
for (int ii = 0; ii < dlSet.size(); ii++) {
final DLSequence dlSequence = (DLSequence) dlSet.getObjectAt(ii);
if (dlSequence.size() != 2) {
throw new DSSException("The DLSequence must contains exactly 2 elements.");
}
final ASN1Encodable asn1EncodableAttributeType = dlSequence.getObjectAt(0);
final String stringAttributeType = getString(asn1EncodableAttributeType);
final ASN1Encodable asn1EncodableAttributeValue = dlSequence.getObjectAt(1);
final String stringAttributeValue = getString(asn1EncodableAttributeValue);
treeMap.put(stringAttributeType, stringAttributeValue);
}
}
return treeMap;
}
代码示例来源:origin: esig/dss
public static Map<String, String> get(final X500Principal x500Principal) {
Map<String, String> treeMap = new HashMap<String, String>();
final byte[] encoded = x500Principal.getEncoded();
final ASN1Sequence asn1Sequence = ASN1Sequence.getInstance(encoded);
final ASN1Encodable[] asn1Encodables = asn1Sequence.toArray();
for (final ASN1Encodable asn1Encodable : asn1Encodables) {
final DLSet dlSet = (DLSet) asn1Encodable;
for (int ii = 0; ii < dlSet.size(); ii++) {
final DLSequence dlSequence = (DLSequence) dlSet.getObjectAt(ii);
if (dlSequence.size() != 2) {
throw new DSSException("The DLSequence must contains exactly 2 elements.");
}
final ASN1Encodable asn1EncodableAttributeType = dlSequence.getObjectAt(0);
final String stringAttributeType = getString(asn1EncodableAttributeType);
final ASN1Encodable asn1EncodableAttributeValue = dlSequence.getObjectAt(1);
final String stringAttributeValue = getString(asn1EncodableAttributeValue);
treeMap.put(stringAttributeType, stringAttributeValue);
}
}
return treeMap;
}
代码示例来源:origin: org.demoiselle.signer/core
/**
* *
* @return the authority key identifier of a certificate
*
*/
public String getAuthorityKeyIdentifier() {
// TODO - Precisa validar este metodo com a RFC
try {
DLSequence sequence = (DLSequence) getExtensionValue(Extension.authorityKeyIdentifier.getId());
if (sequence == null || sequence.size() == 0) {
return null;
}
DERTaggedObject taggedObject = (DERTaggedObject) sequence.getObjectAt(0);
DEROctetString oct = (DEROctetString) taggedObject.getObject();
return toString(oct.getOctets());
} catch (Exception error) {
logger.info(error.getMessage());
return null;
}
}
代码示例来源:origin: com.bushidowallet/bushido-core-lib
public boolean verify(byte[] message, byte[] signature) throws Exception
{
ASN1InputStream asn1 = new ASN1InputStream(signature);
ECDSASigner signer = new ECDSASigner();
//not for signing...
signer.init(false, new ECPublicKeyParameters(curve.getCurve().decodePoint(pub), params));
DLSequence seq = (DLSequence) asn1.readObject();
BigInteger r = ((ASN1Integer) seq.getObjectAt(0)).getPositiveValue();
BigInteger s = ((ASN1Integer) seq.getObjectAt(1)).getPositiveValue();
return signer.verifySignature(message, r, s);
}
代码示例来源:origin: org.demoiselle.signer/signature-core
/**
* Obtém o Identificador de chave de autoridade de um certificado
*
* @return O Identificador de chave de autoridade
* @throws IOException Retorna a exceção IOException
*/
public String getAuthorityKeyIdentifier() throws IOException {
// TODO - Precisa validar este metodo com a RFC
DLSequence sequence = (DLSequence) getExtensionValue(Extension.authorityKeyIdentifier.getId());
if (sequence == null || sequence.size() == 0) {
return null;
}
DERTaggedObject taggedObject = (DERTaggedObject) sequence.getObjectAt(0);
DEROctetString oct = (DEROctetString) taggedObject.getObject();
return toString(oct.getOctets());
}
代码示例来源: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) {
}
}
}
代码示例来源:origin: org.demoiselle.signer/policy-engine
@Override
public void parse(ASN1Primitive derObject) {
ASN1Sequence sequence = ASN1Object.getDERSequence(derObject);
ASN1Primitive policyInfos = sequence.getObjectAt(0).toASN1Primitive();
DLSequence policyInfosSequence = (DLSequence) policyInfos;
if (policyInfosSequence != null && policyInfosSequence.size() > 0) {
this.policyInfos = new ArrayList<>();
for (int i = 0; i < policyInfosSequence.size(); i++) {
PolicyInfo policyInfo = new PolicyInfo();
policyInfo.parse(policyInfosSequence.getObjectAt(i).toASN1Primitive());
this.policyInfos.add(policyInfo);
}
}
this.nextUpdate = new Time();
this.nextUpdate.parse(sequence.getObjectAt(1).toASN1Primitive());
}
代码示例来源:origin: org.demoiselle.signer/policy-engine
public void parse(ASN1Primitive derObject) {
ASN1Sequence sequence = ASN1Object.getDERSequence(derObject);
ASN1Primitive firstObject = sequence.getObjectAt(0).toASN1Primitive();
this.version = new Version();
int indice = 0;
if (firstObject instanceof ASN1Integer) {
this.version.parse(firstObject);
indice++;
}
ASN1Primitive policyInfos = sequence.getObjectAt(indice).toASN1Primitive();
DLSequence policyInfosSequence = (DLSequence) policyInfos;
if (policyInfosSequence != null && policyInfosSequence.size() > 0) {
this.policyInfos = new ArrayList<>();
for (int i = 0; i < policyInfosSequence.size(); i++) {
PolicyInfo policyInfo = new PolicyInfo();
policyInfo.parse(policyInfosSequence.getObjectAt(i).toASN1Primitive());
this.policyInfos.add(policyInfo);
}
}
this.nextUpdate = new GeneralizedTime();
this.nextUpdate.parse(sequence.getObjectAt(indice + 1).toASN1Primitive());
}
内容来源于网络,如有侵权,请联系作者删除!