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

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

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

ASN1Integer介绍

[英]Class representing the ASN.1 INTEGER type.
[中]表示ASN的类。1整数类型。

代码示例

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

private KeyTransRecipientInfo computeRecipientInfo(X509Certificate x509certificate, byte[] abyte0)
  throws IOException, CertificateEncodingException, InvalidKeyException,
    BadPaddingException, IllegalBlockSizeException
{
  TBSCertificate certificate;
  try (ASN1InputStream input = new ASN1InputStream(x509certificate.getTBSCertificate()))
  {
    certificate = TBSCertificate.getInstance(input.readObject());
  }
  AlgorithmIdentifier algorithmId = certificate.getSubjectPublicKeyInfo().getAlgorithm();
  IssuerAndSerialNumber serial = new IssuerAndSerialNumber(
      certificate.getIssuer(),
      certificate.getSerialNumber().getValue());
  Cipher cipher;
  try
  {
    cipher = Cipher.getInstance(algorithmId.getAlgorithm().getId(),
        SecurityProvider.getProvider());
  }
  catch (NoSuchAlgorithmException | NoSuchPaddingException e)
  {
    // should never happen, if this happens throw IOException instead
    throw new RuntimeException("Could not find a suitable javax.crypto provider", e);
  }
  cipher.init(1, x509certificate.getPublicKey());
  DEROctetString octets = new DEROctetString(cipher.doFinal(abyte0));
  RecipientIdentifier recipientId = new RecipientIdentifier(serial);
  return new KeyTransRecipientInfo(recipientId, algorithmId, octets);
}

代码示例来源:origin: hierynomus/sshj

/**
   * Encodes the signature as a DER sequence (ASN.1 format).
   */
  private byte[] asnEncode(byte[] sigBlob) throws IOException {
    Buffer.PlainBuffer sigbuf = new Buffer.PlainBuffer(sigBlob);
    byte[] r = sigbuf.readBytes();
    byte[] s = sigbuf.readBytes();

    ASN1EncodableVector vector = new ASN1EncodableVector();
    vector.add(new ASN1Integer(r));
    vector.add(new ASN1Integer(s));

    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    ASN1OutputStream asnOS = new ASN1OutputStream(baos);

    asnOS.writeObject(new DERSequence(vector));
    asnOS.flush();

    return baos.toByteArray();
  }
}

代码示例来源:origin: org.apache.poi/poi-ooxml

private BigInteger getCrlNumber(X509CRL crl) {
  byte[] crlNumberExtensionValue = crl.getExtensionValue(Extension.cRLNumber.getId());
  if (null == crlNumberExtensionValue) {
    return null;
  }
  try {
    ASN1InputStream asn1IS1 = null, asn1IS2 = null;
    try {
      asn1IS1 = new ASN1InputStream(crlNumberExtensionValue);
      ASN1OctetString octetString = (ASN1OctetString)asn1IS1.readObject();
      byte[] octets = octetString.getOctets();
      asn1IS2 = new ASN1InputStream(octets);
      ASN1Integer integer = (ASN1Integer)asn1IS2.readObject();
      return integer.getPositiveValue();
    } finally {
      IOUtils.closeQuietly(asn1IS2);
      IOUtils.closeQuietly(asn1IS1);
    }
  } catch (IOException e) {
    throw new RuntimeException("I/O error: " + e.getMessage(), e);
  }
}

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

private RSAPublicKey(
  ASN1Sequence seq)
{
  if (seq.size() != 2)
  {
    throw new IllegalArgumentException("Bad sequence size: "
        + seq.size());
  }
  Enumeration e = seq.getObjects();
  modulus = ASN1Integer.getInstance(e.nextElement()).getPositiveValue();
  publicExponent = ASN1Integer.getInstance(e.nextElement()).getPositiveValue();
}

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

private DHParameter(
  ASN1Sequence  seq)
{
  Enumeration     e = seq.getObjects();
  p = ASN1Integer.getInstance(e.nextElement());
  g = ASN1Integer.getInstance(e.nextElement());
  if (e.hasMoreElements())
  {
    l = (ASN1Integer)e.nextElement();
  }
  else
  {
    l = null;
  }
}

代码示例来源: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: org.bouncycastle/bcprov-debug-jdk15on

private LDSSecurityObject(
  ASN1Sequence seq)
{
  if (seq == null || seq.size() == 0)
  {
    throw new IllegalArgumentException("null or empty sequence passed.");
  }
  Enumeration e = seq.getObjects();
  // version
  version = ASN1Integer.getInstance(e.nextElement());
  // digestAlgorithmIdentifier
  digestAlgorithmIdentifier = AlgorithmIdentifier.getInstance(e.nextElement());
  ASN1Sequence datagroupHashSeq = ASN1Sequence.getInstance(e.nextElement());
  if (version.getValue().intValue() == 1)
  {
    versionInfo = LDSVersionInfo.getInstance(e.nextElement());
  }
  checkDatagroupHashSeqSize(datagroupHashSeq.size());
  datagroupHash = new DataGroupHash[datagroupHashSeq.size()];
  for (int i = 0; i < datagroupHashSeq.size(); i++)
  {
    datagroupHash[i] = DataGroupHash.getInstance(datagroupHashSeq.getObjectAt(i));
  }
}

代码示例来源: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 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: hierynomus/sshj

/**
   * Encodes the signature as a DER sequence (ASN.1 format).
   */
  private byte[] asnEncode(byte[] sigBlob) throws IOException {
    byte[] r = new BigInteger(1, Arrays.copyOfRange(sigBlob, 0, 20)).toByteArray();
    byte[] s = new BigInteger(1, Arrays.copyOfRange(sigBlob, 20, 40)).toByteArray();

    ASN1EncodableVector vector = new ASN1EncodableVector();
    vector.add(new ASN1Integer(r));
    vector.add(new ASN1Integer(s));

    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    ASN1OutputStream asnOS = new ASN1OutputStream(baos);

    asnOS.writeObject(new DERSequence(vector));
    asnOS.flush();

    return baos.toByteArray();
  }
}

代码示例来源: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: redfish64/TinyTravelTracker

private McElieceCCA2PublicKey(ASN1Sequence seq)
{
  oid = ((ASN1ObjectIdentifier)seq.getObjectAt(0));
  BigInteger bigN = ((ASN1Integer)seq.getObjectAt(1)).getValue();
  n = bigN.intValue();
  BigInteger bigT = ((ASN1Integer)seq.getObjectAt(2)).getValue();
  t = bigT.intValue();
  matrixG = ((ASN1OctetString)seq.getObjectAt(3)).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 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: 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 XMSSMTKeyParams(ASN1Sequence sequence)
{
  this.version = ASN1Integer.getInstance(sequence.getObjectAt(0));
  this.height = ASN1Integer.getInstance(sequence.getObjectAt(1)).getValue().intValue();
  this.layers = ASN1Integer.getInstance(sequence.getObjectAt(2)).getValue().intValue();
  this.treeDigest = AlgorithmIdentifier.getInstance(sequence.getObjectAt(3));
}

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

public static TypeOfBiometricData getInstance(Object obj)
{
  if (obj == null || obj instanceof TypeOfBiometricData)
  {
    return (TypeOfBiometricData)obj;
  }
  if (obj instanceof ASN1Integer)
  {
    ASN1Integer predefinedBiometricTypeObj = ASN1Integer.getInstance(obj);
    int  predefinedBiometricType = predefinedBiometricTypeObj.getValue().intValue();
    return new TypeOfBiometricData(predefinedBiometricType);
  }
  else if (obj instanceof ASN1ObjectIdentifier)
  {
    ASN1ObjectIdentifier BiometricDataID = ASN1ObjectIdentifier.getInstance(obj);
    return new TypeOfBiometricData(BiometricDataID);
  }
  throw new IllegalArgumentException("unknown object in getInstance");
}

代码示例来源:origin: org.xipki/security

private List<Long> getMechanismsFromServer() throws P11TokenException {
 ProxyMessage.SlotIdentifier asn1SlotId = new ProxyMessage.SlotIdentifier(slotId);
 byte[] resp = module.send(P11ProxyConstants.ACTION_GET_MECHANISMS, asn1SlotId);
 ASN1Sequence seq = requireSequence(resp);
 final int n = seq.size();
 List<Long> mechs = new ArrayList<>(n);
 for (int i = 0; i < n; i++) {
  long mech = ASN1Integer.getInstance(seq.getObjectAt(i)).getValue().longValue();
  mechs.add(mech);
 }
 return mechs;
}

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

AsymmetricKeyParameter getPublicKeyParameters(SubjectPublicKeyInfo keyInfo, Object defaultParams)
    throws IOException
  {
    DHParameter params = DHParameter.getInstance(keyInfo.getAlgorithm().getParameters());
    ASN1Integer derY = (ASN1Integer)keyInfo.parsePublicKey();
    BigInteger lVal = params.getL();
    int l = lVal == null ? 0 : lVal.intValue();
    DHParameters dhParams = new DHParameters(params.getP(), params.getG(), null, l);
    return new DHPublicKeyParameters(derY.getValue(), dhParams);
  }
}

相关文章