org.bouncycastle.asn1.ASN1Sequence类的使用及代码示例

x33g5p2x  于11个月前 转载在 其他  
字(11.8k)|赞(0)|评价(0)|浏览(48)

本文整理了Java中org.bouncycastle.asn1.ASN1Sequence类的一些代码示例,展示了ASN1Sequence类的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。ASN1Sequence类的具体详情如下:
包路径:org.bouncycastle.asn1.ASN1Sequence
类名称:ASN1Sequence

ASN1Sequence介绍

[英]ASN.1 SEQUENCE and SEQUENCE OF constructs.

DER form is always definite form length fields, while BER support uses indefinite form.

X.690

8: Basic encoding rules

8.9 Encoding of a sequence value
8.9.1 The encoding of a sequence value shall be constructed.

8.9.2 The contents octets shall consist of the complete encoding of one data value from each of the types listed in the ASN.1 definition of the sequence type, in the order of their appearance in the definition, unless the type was referenced with the keyword OPTIONAL or the keyword DEFAULT.

8.9.3 The encoding of a data value may, but need not, be present for a type which was referenced with the keyword OPTIONAL or the keyword DEFAULT. If present, it shall appear in the encoding at the point corresponding to the appearance of the type in the ASN.1 definition.

8.10 Encoding of a sequence-of value

8.10.1 The encoding of a sequence-of value shall be constructed.

8.10.2 The contents octets shall consist of zero, one or more complete encodings of data values from the type listed in the ASN.1 definition.

8.10.3 The order of the encodings of the data values shall be the same as the order of the data values in the sequence-of value to be encoded.

9: Canonical encoding rules

9.1 Length forms
If the encoding is constructed, it shall employ the indefinite length form. If the encoding is primitive, it shall include the fewest length octets necessary. [Contrast with 8.1.3.2 b).]

11: Restrictions on BER employed by both CER and DER

11.5 Set and sequence components with default value
The encoding of a set value or sequence value shall not include an encoding for any component value which is equal to its default value.
[中]ASN。1SEQUENCESEQUENCE OF构造。
DER form始终是确定格式长度字段,而BER支持使用不确定格式。
X.690
8:基本编码规则
8.9序列值的编码
8.9.1应构造序列值的编码。
8.9.2内容八位字节应包括ASN中列出的每种类型的一个数据值的完整编码。1序列类型的定义,按照其在定义中的出现顺序,除非使用关键字OPTIONAL或关键字DEFAULT引用该类型。
8.9.3对于使用关键字OPTIONAL或关键字DEFAULT引用的类型,数据值的编码可能存在,但无需存在。如果存在,则其应出现在编码中与ASN中类型外观相对应的点处。1定义。
8.10值序列的编码
8.10.1应构造值序列的编码。
8.10.2内容八位字节应由ASN中所列类型的零、一个或多个完整数据值编码组成。1定义。
8.10.3数据值的编码顺序应与待编码值序列中的数据值顺序相同。
9:规范编码规则
9.1长度表格
如果构造了编码,则应采用不定长形式。如果编码为原始编码,则应包含所需的最小长度的八位字节。[与8.1.3.2 b相比。]
11:CER和DER对BER的限制
11.5使用默认值设置和排序组件
设定值或序列值的编码不应包括等于其默认值的任何组件值的编码。

代码示例

代码示例来源:origin: apache/pdfbox

byte[] authorityExtensionValue = cert.getExtensionValue(Extension.authorityInfoAccess.getId());
if (authorityExtensionValue != null)
  Enumeration<?> objects = asn1Seq.getObjects();
  while (objects.hasMoreElements())
    ASN1Sequence obj = (ASN1Sequence) objects.nextElement();
    ASN1ObjectIdentifier oid = (ASN1ObjectIdentifier) obj.getObjectAt(0);
    DERTaggedObject location = (DERTaggedObject) obj.getObjectAt(1);
    if (oid.equals(X509ObjectIdentifiers.id_ad_ocsp)
        && location.getTagNo() == GeneralName.uniformResourceIdentifier)

代码示例来源:origin: cloudfoundry/uaa

KeyFactory fact = KeyFactory.getInstance("RSA");
if (type.equals("RSA PRIVATE KEY")) {
  ASN1Sequence seq = ASN1Sequence.getInstance(content);
  if (seq.size() != 9) {
    throw new IllegalArgumentException("Invalid RSA Private Key ASN1 sequence.");
  publicKey = fact.generatePublic(keySpec);
} else if (type.equals("RSA PUBLIC KEY")) {
  ASN1Sequence seq = ASN1Sequence.getInstance(content);
  org.bouncycastle.asn1.pkcs.RSAPublicKey key = org.bouncycastle.asn1.pkcs.RSAPublicKey.getInstance(seq);
  RSAPublicKeySpec pubSpec = new RSAPublicKeySpec(key.getModulus(), key.getPublicExponent());

代码示例来源:origin: stackoverflow.com

DERApplicationSpecific app = (DERApplicationSpecific) obj;
ASN1Sequence seq = (ASN1Sequence) app.getObject(BERTags.SEQUENCE);
Enumeration secEnum = seq.getObjects();
while (secEnum.hasMoreElements()) {
  ASN1Primitive seqObj = (ASN1Primitive) secEnum.nextElement();
  System.out.println(seqObj);
}

代码示例来源:origin: org.bouncycastle/bcprov-debug-jdk15on

private DSAParameter(
  ASN1Sequence  seq)
{
  if (seq.size() != 3)
  {
    throw new IllegalArgumentException("Bad sequence size: " + seq.size());
  }
  
  Enumeration     e = seq.getObjects();
  p = ASN1Integer.getInstance(e.nextElement());
  q = ASN1Integer.getInstance(e.nextElement());
  g = ASN1Integer.getInstance(e.nextElement());
}

代码示例来源:origin: redfish64/TinyTravelTracker

/**
 * @deprecated use PrivateKeyInfo.getInstance()
 * @param seq
 */
public PrivateKeyInfo(
  ASN1Sequence  seq)
{
  Enumeration e = seq.getObjects();
  BigInteger  version = ((ASN1Integer)e.nextElement()).getValue();
  if (version.intValue() != 0)
  {
    throw new IllegalArgumentException("wrong version for private key info");
  }
  algId = AlgorithmIdentifier.getInstance(e.nextElement());
  privKey = ASN1OctetString.getInstance(e.nextElement());
  
  if (e.hasMoreElements())
  {
    attributes = ASN1Set.getInstance((ASN1TaggedObject)e.nextElement(), false);
  }
}

代码示例来源:origin: open-eid/digidoc4j

/**
 * Returns current certificate policies or null if no policies was found.
 *
 * @return list of policies
 * @throws IOException when policy parsing fails
 */
public List<String> getCertificatePolicies() throws IOException {
 logger.debug("");
 byte[] extensionValue = originalCert.getExtensionValue("2.5.29.32");
 List<String> policies = new ArrayList<>();
 byte[] octets = ((DEROctetString) DEROctetString.fromByteArray(extensionValue)).getOctets();
 ASN1Sequence sequence = (ASN1Sequence) ASN1Sequence.fromByteArray(octets);
 Enumeration sequenceObjects = sequence.getObjects();
 while (sequenceObjects.hasMoreElements()) {
  DLSequence next = (DLSequence) sequenceObjects.nextElement();
  Object objectAt = next.getObjectAt(0);
  if (objectAt != null) {
   policies.add(objectAt.toString());
  }
 }
 return policies;
}

代码示例来源:origin: redfish64/TinyTravelTracker

private TSTInfo(ASN1Sequence seq)
  Enumeration e = seq.getObjects();
  version = ASN1Integer.getInstance(e.nextElement());
  tsaPolicyId = ASN1ObjectIdentifier.getInstance(e.nextElement());
  messageImprint = MessageImprint.getInstance(e.nextElement());
  serialNumber = ASN1Integer.getInstance(e.nextElement());
      nonce = ASN1Integer.getInstance(o);

代码示例来源:origin: org.bouncycastle/bcprov-debug-jdk15on

public GOST3410ParamSetParameters(
  ASN1Sequence  seq)
{
  Enumeration     e = seq.getObjects();
  keySize = ((ASN1Integer)e.nextElement()).getValue().intValue();
  p = (ASN1Integer)e.nextElement();
  q = (ASN1Integer)e.nextElement();
  a = (ASN1Integer)e.nextElement();
}

代码示例来源:origin: org.bouncycastle/bcprov-debug-jdk15on

private EncryptedPrivateKeyInfo(
  ASN1Sequence  seq)
{
  Enumeration e = seq.getObjects();
  algId = AlgorithmIdentifier.getInstance(e.nextElement());
  data = ASN1OctetString.getInstance(e.nextElement());
}

代码示例来源:origin: org.bouncycastle/bcprov-debug-jdk15on

private DataGroupHash(ASN1Sequence seq)
{
  Enumeration e = seq.getObjects();
  // dataGroupNumber
  dataGroupNumber = ASN1Integer.getInstance(e.nextElement());
  // dataGroupHashValue
  dataGroupHashValue = ASN1OctetString.getInstance(e.nextElement());   
}

代码示例来源:origin: org.bouncycastle/bcprov-debug-jdk15on

private MonetaryValue(
  ASN1Sequence seq)
{
  Enumeration e = seq.getObjects();    
  // currency
  currency = Iso4217CurrencyCode.getInstance(e.nextElement());
  // hashAlgorithm
  amount = ASN1Integer.getInstance(e.nextElement());
  // exponent
  exponent = ASN1Integer.getInstance(e.nextElement());            
}

代码示例来源:origin: org.cryptacular/cryptacular

/**
  * Parses an EC private key as defined in RFC 5915.
  * <pre>
  *      ECPrivateKey ::= SEQUENCE {
  *        version        INTEGER { ecPrivkeyVer1(1) } (ecPrivkeyVer1),
  *        privateKey     OCTET STRING,
  *        parameters [0] ECParameters {{ NamedCurve }} OPTIONAL,
  *        publicKey  [1] BIT STRING OPTIONAL
  *      }
  * </pre>
  *
  * @param  seq  ASN1 sequence to parse
  *
  * @return  EC private key
  */
 private ECPrivateKeyParameters parseECPrivateKey(final ASN1Sequence seq)
 {
  final ASN1TaggedObject asn1Params = ASN1TaggedObject.getInstance(seq.getObjectAt(2));
  final X9ECParameters params;
  if (asn1Params.getObject() instanceof ASN1ObjectIdentifier) {
   params = ECUtil.getNamedCurveByOid(ASN1ObjectIdentifier.getInstance(asn1Params.getObject()));
  } else {
   params = X9ECParameters.getInstance(asn1Params.getObject());
  }
  return new ECPrivateKeyParameters(
   new BigInteger(1, ASN1OctetString.getInstance(seq.getObjectAt(1)).getOctets()),
   new ECDomainParameters(params.getCurve(), params.getG(), params.getN(), params.getH(), params.getSeed()));
 }
}

代码示例来源:origin: org.bouncycastle/bcprov-debug-jdk15on

private McElieceCCA2PrivateKey(ASN1Sequence seq)
{
  BigInteger bigN = ((ASN1Integer)seq.getObjectAt(0)).getValue();
  n = bigN.intValue();
  BigInteger bigK = ((ASN1Integer)seq.getObjectAt(1)).getValue();
  k = bigK.intValue();
  encField = ((ASN1OctetString)seq.getObjectAt(2)).getOctets();
  encGp = ((ASN1OctetString)seq.getObjectAt(3)).getOctets();
  encP = ((ASN1OctetString)seq.getObjectAt(4)).getOctets();
  digest = AlgorithmIdentifier.getInstance(seq.getObjectAt(5));
}

代码示例来源:origin: org.bouncycastle/bcprov-debug-jdk15on

private XMSSMTPublicKey(ASN1Sequence seq)
{
  if (!ASN1Integer.getInstance(seq.getObjectAt(0)).getValue().equals(BigInteger.valueOf(0)))
  {
    throw new IllegalArgumentException("unknown version of sequence");
  }
  this.publicSeed = Arrays.clone(DEROctetString.getInstance(seq.getObjectAt(1)).getOctets());
  this.root = Arrays.clone(DEROctetString.getInstance(seq.getObjectAt(2)).getOctets());
}

代码示例来源:origin: org.bouncycastle/bcprov-debug-jdk15on

throws IOException
ASN1Sequence    seq = ASN1Sequence.getInstance(info.getPrivateKeyAlgorithm().getParameters());
ASN1Integer      derX = ASN1Integer.getInstance(info.parsePrivateKey());
ASN1ObjectIdentifier id = info.getPrivateKeyAlgorithm().getAlgorithm();
this.x = derX.getValue();
if (id.equals(PKCSObjectIdentifiers.dhKeyAgreement))
    this.dhSpec = new DHParameterSpec(params.getP(), params.getG(), params.getL().intValue());
else if (id.equals(X9ObjectIdentifiers.dhpublicnumber))
  this.dhSpec = new DHParameterSpec(params.getP().getValue(), params.getG().getValue());

代码示例来源:origin: org.bouncycastle/bcprov-debug-jdk15on

private EncryptedData(
  ASN1Sequence seq)
{
  int version = ((ASN1Integer)seq.getObjectAt(0)).getValue().intValue();
  if (version != 0)
  {
    throw new IllegalArgumentException("sequence not version 0");
  }
  this.data = ASN1Sequence.getInstance(seq.getObjectAt(1));
}

代码示例来源:origin: org.bouncycastle/bcprov-debug-jdk15on

private XMSSKeyParams(ASN1Sequence sequence)
{
  this.version = ASN1Integer.getInstance(sequence.getObjectAt(0));
  this.height = ASN1Integer.getInstance(sequence.getObjectAt(1)).getValue().intValue();
  this.treeDigest = AlgorithmIdentifier.getInstance(sequence.getObjectAt(2));
}

代码示例来源:origin: org.cryptacular/cryptacular

final org.bouncycastle.asn1.pkcs.EncryptionScheme scheme)
final PBES2Algorithm alg = PBES2Algorithm.fromOid(scheme.getAlgorithm().getId());
if (keyLength == 0) {
 keyLength = alg.getKeySize();
 setCipher(alg.getCipherSpec().newInstance());
 final ASN1Sequence rc2Params = ASN1Sequence.getInstance(scheme.getParameters());
 if (rc2Params.size() > 1) {
  cipherParameters = new RC2Parameters(
   ((KeyParameter) cipherParameters).getKey(),
   ASN1Integer.getInstance(rc2Params.getObjectAt(0)).getValue().intValue());
  iv = ASN1OctetString.getInstance(rc2Params.getObjectAt(0)).getOctets();
 final ASN1Sequence rc5Params = ASN1Sequence.getInstance(scheme.getParameters());
 final int rounds = ASN1Integer.getInstance(rc5Params.getObjectAt(1)).getValue().intValue();
 final int blockSize = ASN1Integer.getInstance(rc5Params.getObjectAt(2)).getValue().intValue();
 if (blockSize == 32) {
  setCipher(new PaddedBufferedBlockCipher(new CBCBlockCipher(new RC532Engine()), new PKCS7Padding()));
 if (rc5Params.size() > 3) {
  iv = ASN1OctetString.getInstance(rc5Params.getObjectAt(3)).getOctets();

代码示例来源:origin: org.bouncycastle/bcprov-debug-jdk15on

private GCMParameters(
  ASN1Sequence seq)
{
  this.nonce = ASN1OctetString.getInstance(seq.getObjectAt(0)).getOctets();
  if (seq.size() == 2)
  {
    this.icvLen = ASN1Integer.getInstance(seq.getObjectAt(1)).getValue().intValue();
  }
  else
  {
    this.icvLen = 12;
  }
}

代码示例来源:origin: ontio/ontology-java-sdk

private byte[] DSADERtoPlain(byte[] sig) throws IOException {
  ASN1Sequence seq = (ASN1Sequence) ASN1Primitive.fromByteArray(sig);
  if (seq.size() != 2) {
    throw new IOException(ErrorCode.MalformedSignature);
  } else if (!Arrays.equals(sig, seq.getEncoded("DER"))) {
    throw new IOException(ErrorCode.MalformedSignature);
  }
  byte[] r = ASN1Integer.getInstance(seq.getObjectAt(0)).getValue().toByteArray();
  byte[] s = ASN1Integer.getInstance(seq.getObjectAt(1)).getValue().toByteArray();
  int ri = (r[0] == 0) ? 1 : 0;
  int rl = r.length - ri;
  int si = (s[0] == 0) ? 1 : 0;
  int sl = s.length - si;
  byte[] res;
  if (rl > sl) {
    res = new byte[rl * 2];
  } else {
    res = new byte[sl * 2];
  }
  System.arraycopy(r, ri, res, res.length/2 - rl, rl);
  System.arraycopy(s, si, res, res.length-sl, sl);
  return res;
}

相关文章