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

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

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

AlgorithmIdentifier介绍

暂无

代码示例

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

private ASN1Primitive createDERForRecipient(byte[] in, X509Certificate cert)
    throws IOException, GeneralSecurityException
  String algorithm = PKCSObjectIdentifiers.RC2_CBC.getId();
  AlgorithmParameterGenerator apg;
  KeyGenerator keygen;
  DERSet set = new DERSet(new RecipientInfo(recipientInfo));
  AlgorithmIdentifier algorithmId = new AlgorithmIdentifier(new ASN1ObjectIdentifier(algorithm), object);
  EncryptedContentInfo encryptedInfo = 
      new EncryptedContentInfo(PKCSObjectIdentifiers.data, algorithmId, new DEROctetString(bytes));

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

BCGOST3410PrivateKey(
  PrivateKeyInfo info)
  throws IOException
{
  GOST3410PublicKeyAlgParameters    params = GOST3410PublicKeyAlgParameters.getInstance(info.getPrivateKeyAlgorithm().getParameters());
  ASN1Encodable privKey = info.parsePrivateKey();
  if (privKey instanceof ASN1Integer)
  {
    this.x = ASN1Integer.getInstance(privKey).getPositiveValue();
  }
  else
  {
    ASN1OctetString derX = ASN1OctetString.getInstance(info.parsePrivateKey());
    byte[] keyEnc = derX.getOctets();
    byte[] keyBytes = new byte[keyEnc.length];
    for (int i = 0; i != keyEnc.length; i++)
    {
      keyBytes[i] = keyEnc[keyEnc.length - 1 - i]; // was little endian
    }
    this.x = new BigInteger(1, keyBytes);
  }
  this.gost3410Spec = GOST3410ParameterSpec.fromPublicKeyAlg(params);
}

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

protected void engineInit(
  byte[] params) 
  throws IOException
{
  try
  {
    RSASSAPSSparams pssP = RSASSAPSSparams.getInstance(params);
    if (!pssP.getMaskGenAlgorithm().getAlgorithm().equals(PKCSObjectIdentifiers.id_mgf1))
    {
      throw new IOException("unknown mask generation function: " + pssP.getMaskGenAlgorithm().getAlgorithm());
    }
    currentSpec = new PSSParameterSpec(
                MessageDigestUtils.getDigestName(pssP.getHashAlgorithm().getAlgorithm()),
                PSSParameterSpec.DEFAULT.getMGFAlgorithm(),
                new MGF1ParameterSpec(MessageDigestUtils.getDigestName(AlgorithmIdentifier.getInstance(pssP.getMaskGenAlgorithm().getParameters()).getAlgorithm())),
                pssP.getSaltLength().intValue(),
                pssP.getTrailerField().intValue());
  }
  catch (ClassCastException e)
  {
    throw new IOException("Not a valid PSS Parameter encoding.");
  }
  catch (ArrayIndexOutOfBoundsException e)
  {
    throw new IOException("Not a valid PSS Parameter encoding.");
  }
}

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

params = new DSTU4145Params(new ASN1ObjectIdentifier(((ECNamedCurveSpec)ecSpec).getName()));
    EC5Util.convertPoint(curve, ecSpec.getGenerator(), withCompression),
    ecSpec.getOrder(),
    BigInteger.valueOf(ecSpec.getCofactor()),
    ecSpec.getCurve().getSeed());
info = new SubjectPublicKeyInfo(new AlgorithmIdentifier(UAObjectIdentifiers.dstu4145be, params), new DEROctetString(encKey));

代码示例来源:origin: org.xipki/ca-api

public RSAKeypairGenControl(int keysize, BigInteger publicExponent,
  ASN1ObjectIdentifier keyAlgorithmOid) {
 if (keysize < 1024 || keysize % 512 != 0) {
  throw new IllegalArgumentException("invalid keysize " + keysize);
 }
 this.keysize = keysize;
 this.publicExponent = (publicExponent != null) ? publicExponent
   : BigInteger.valueOf(0x10001);
 this.keyAlgorithm = new AlgorithmIdentifier(
   (keyAlgorithmOid != null) ? keyAlgorithmOid : PKCSObjectIdentifiers.rsaEncryption,
   DERNull.INSTANCE);
}

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

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 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 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.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);
  }
}

代码示例来源:origin: com.hynnet/jradius-extended

throws IOException
AlgorithmIdentifier     algId = keyInfo.getAlgorithmId();
if (algId.getObjectId().equals(PKCSObjectIdentifiers.rsaEncryption))
  RSAPrivateKeyStructure  keyStructure = new RSAPrivateKeyStructure((ASN1Sequence)keyInfo.getPrivateKey());
else if (algId.getObjectId().equals(PKCSObjectIdentifiers.dhKeyAgreement))
  DHParameter     params = new DHParameter((ASN1Sequence)keyInfo.getAlgorithmId().getParameters());
  DERInteger      derX = (DERInteger)keyInfo.getPrivateKey();
else if (algId.getObjectId().equals(OIWObjectIdentifiers.elGamalAlgorithm))
  ElGamalParameter    params = new ElGamalParameter((ASN1Sequence)keyInfo.getAlgorithmId().getParameters());
  DERInteger          derX = (DERInteger)keyInfo.getPrivateKey();
else if (algId.getObjectId().equals(X9ObjectIdentifiers.id_dsa))
  DERInteger derX = (DERInteger)keyInfo.getPrivateKey();
  DEREncodable de = keyInfo.getAlgorithmId().getParameters();
else if (algId.getObjectId().equals(X9ObjectIdentifiers.id_ecPublicKey))
  X962Parameters      params = new X962Parameters((DERObject)keyInfo.getAlgorithmId().getParameters());
  ECDomainParameters  dParams = null;

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

try
  derY = (ASN1Integer)info.parsePublicKey();
this.y = derY.getValue();
ASN1Sequence seq = ASN1Sequence.getInstance(info.getAlgorithm().getParameters());
ASN1ObjectIdentifier id = info.getAlgorithm().getAlgorithm();
if (id.equals(PKCSObjectIdentifiers.dhKeyAgreement) || isPKCSParam(seq))
    this.dhSpec = new DHParameterSpec(params.getP(), params.getG(), params.getL().intValue());
else if (id.equals(X9ObjectIdentifiers.dhpublicnumber))
                  new DHValidationParameters(validationParams.getSeed(), validationParams.getPgenCounter().intValue())));

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

try
  derY = (ASN1Integer)info.parsePublicKey();
this.y = derY.getValue();
ASN1Sequence seq = ASN1Sequence.getInstance(info.getAlgorithmId().getParameters());
ASN1ObjectIdentifier id = info.getAlgorithmId().getAlgorithm();
if (id.equals(PKCSObjectIdentifiers.dhKeyAgreement) || isPKCSParam(seq))
    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: 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

byte[]                  keyEnc = this.getX().toByteArray();
byte[]                  keyBytes;
    info = new PrivateKeyInfo(new AlgorithmIdentifier(CryptoProObjectIdentifiers.gostR3410_94, new GOST3410PublicKeyAlgParameters(new ASN1ObjectIdentifier(gost3410Spec.getPublicKeyParamSetOID()), new ASN1ObjectIdentifier(gost3410Spec.getDigestParamSetOID()))), new DEROctetString(keyBytes));
    info = new PrivateKeyInfo(new AlgorithmIdentifier(CryptoProObjectIdentifiers.gostR3410_94), new DEROctetString(keyBytes));
  return info.getEncoded(ASN1Encoding.DER);

代码示例来源:origin: xipki/xipki

protected static MyKeypair generateEcKeypair() throws GeneralSecurityException {
 KeyPairGenerator kpGen = KeyPairGenerator.getInstance("EC");
 ECGenParameterSpec spec = new ECGenParameterSpec("secp256r1");
 kpGen.initialize(spec);
 KeyPair kp = kpGen.generateKeyPair();
 ECPublicKey pub = (ECPublicKey) kp.getPublic();
 byte[] keyData = new byte[65];
 keyData[0] = 4;
 copyArray(pub.getW().getAffineX().toByteArray(), keyData, 1, 32);
 copyArray(pub.getW().getAffineY().toByteArray(), keyData, 33, 32);
 AlgorithmIdentifier algId = new AlgorithmIdentifier(
   X9ObjectIdentifiers.id_ecPublicKey, SECObjectIdentifiers.secp256r1);
 SubjectPublicKeyInfo subjectPublicKeyInfo = new SubjectPublicKeyInfo(algId, keyData);
 return new MyKeypair(kp.getPrivate(), subjectPublicKeyInfo);
}

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

private KeyPairWithSubjectPublicKeyInfo genECKeypair(String curveNameOrOid, SecureRandom random)
  throws Exception {
 ASN1ObjectIdentifier curveOid = AlgorithmUtil.getCurveOidForCurveNameOrOid(curveNameOrOid);
 if (curveOid == null) {
  throw new IllegalArgumentException("invalid curveNameOrOid '" + curveNameOrOid + "'");
 }
 KeyPair kp = KeyUtil.generateECKeypair(curveOid, random);
 AlgorithmIdentifier algId = new AlgorithmIdentifier(
   X9ObjectIdentifiers.id_ecPublicKey, curveOid);
 ECPublicKey pub = (ECPublicKey) kp.getPublic();
 int orderBitLength = pub.getParams().getOrder().bitLength();
 byte[] keyData = KeyUtil.getUncompressedEncodedECPoint(pub.getW(), orderBitLength);
 SubjectPublicKeyInfo subjectPublicKeyInfo = new SubjectPublicKeyInfo(algId, keyData);
 return new KeyPairWithSubjectPublicKeyInfo(kp, subjectPublicKeyInfo);
}

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

private MessageImprint(
  ASN1Sequence seq)
{
  this.hashAlgorithm = AlgorithmIdentifier.getInstance(seq.getObjectAt(0));
  this.hashedMessage = ASN1OctetString.getInstance(seq.getObjectAt(1)).getOctets();
}

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

static String getSignatureName(
  AlgorithmIdentifier sigAlgId) 
{
  ASN1Encodable params = sigAlgId.getParameters();
  
  if (params != null && !derNull.equals(params))
  {
    if (sigAlgId.getAlgorithm().equals(PKCSObjectIdentifiers.id_RSASSA_PSS))
    {
      RSASSAPSSparams rsaParams = RSASSAPSSparams.getInstance(params);
      
      return getDigestAlgName(rsaParams.getHashAlgorithm().getAlgorithm()) + "withRSAandMGF1";
    }
    if (sigAlgId.getAlgorithm().equals(X9ObjectIdentifiers.ecdsa_with_SHA2))
    {
      ASN1Sequence ecDsaParams = ASN1Sequence.getInstance(params);
      
      return getDigestAlgName(ASN1ObjectIdentifier.getInstance(ecDsaParams.getObjectAt(0))) + "withECDSA";
    }
  }
  return sigAlgId.getAlgorithm().getId();
}

相关文章