org.bouncycastle.asn1.x509.SubjectPublicKeyInfo.<init>()方法的使用及代码示例

x33g5p2x  于2022-01-30 转载在 其他  
字(9.4k)|赞(0)|评价(0)|浏览(72)

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

SubjectPublicKeyInfo.<init>介绍

暂无

代码示例

代码示例来源:origin: JZ-Darkal/AndroidHttpCapture

private static SubjectKeyIdentifier createSubjectKeyIdentifier(Key key)
    throws IOException {
  ByteArrayInputStream bIn = new ByteArrayInputStream(key.getEncoded());
  ASN1InputStream is = null;
  try {
    is = new ASN1InputStream(bIn);
    ASN1Sequence seq = (ASN1Sequence) is.readObject();
    SubjectPublicKeyInfo info = new SubjectPublicKeyInfo(seq);
    return new BcX509ExtensionUtils().createSubjectKeyIdentifier(info);
  } finally {
    IOUtils.closeQuietly(is);
  }
}

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

/**
 * Returns a {@link PEMKeyPair} object with direct access to the public and private keys given a PKCS #8 private key.
 *
 * @param privateKeyInfo the PKCS #8 private key info
 * @return the PKCS #1 public and private key pair
 * @throws IOException if there is an error converting the key pair
 */
private static PEMKeyPair convertPrivateKeyFromPKCS8ToPKCS1(PrivateKeyInfo privateKeyInfo) throws IOException {
  // Parse the key wrapping to determine the internal key structure
  ASN1Encodable asn1PrivateKey = privateKeyInfo.parsePrivateKey();
  // Convert the parsed key to an RSA private key
  RSAPrivateKey keyStruct = RSAPrivateKey.getInstance(asn1PrivateKey);
  // Create the RSA public key from the modulus and exponent
  RSAPublicKey pubSpec = new RSAPublicKey(
    keyStruct.getModulus(), keyStruct.getPublicExponent());
  // Create an algorithm identifier for forming the key pair
  AlgorithmIdentifier algId = new AlgorithmIdentifier(PKCSObjectIdentifiers.rsaEncryption, DERNull.INSTANCE);
  if (isVerbose()) {
    logger.info("Converted private key from PKCS #8 to PKCS #1 RSA private key");
  }
  // Create the key pair container
  return new PEMKeyPair(new SubjectPublicKeyInfo(algId, pubSpec), new PrivateKeyInfo(algId, keyStruct));
}

代码示例来源:origin: linkedin/flashback

/**
 * Create subjectKeyIdentifier
 * The Subject Key Identifier extension identifies the public key certified by this certificate.
 * This extension provides a way of distinguishing public keys if more than one is available for
 * a given subject name.
 * i.e.
 *     Identifier: Subject Key Identifier - 2.5.29.14
 *       Critical: no
 *        Key Identifier:
 *          3B:46:83:85:27:BC:F5:9D:8E:63:E3:BE:79:EF:AF:79:
 *          9C:37:85:84
 *
 * */
protected SubjectKeyIdentifier createSubjectKeyIdentifier(PublicKey publicKey)
  throws IOException {
 try (ByteArrayInputStream bais = new ByteArrayInputStream(publicKey.getEncoded());
   ASN1InputStream ais = new ASN1InputStream(bais)) {
  ASN1Sequence asn1Sequence = (ASN1Sequence) ais.readObject();
  SubjectPublicKeyInfo subjectPublicKeyInfo = new SubjectPublicKeyInfo(asn1Sequence);
  return new BcX509ExtensionUtils().createSubjectKeyIdentifier(subjectPublicKeyInfo);
 }
}

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

public static byte[] getEncodedSubjectPublicKeyInfo(AlgorithmIdentifier algId, ASN1Encodable keyData)
{
  try
  {
    return getEncodedSubjectPublicKeyInfo(new SubjectPublicKeyInfo(algId, keyData));
  }
  catch (Exception e)
  {
    return null;
  }
}

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

public static byte[] getEncodedSubjectPublicKeyInfo(AlgorithmIdentifier algId, byte[] keyData)
{
  try
  {
    return getEncodedSubjectPublicKeyInfo(new SubjectPublicKeyInfo(algId, keyData));
  }
  catch (Exception e)
  {
    return null;
  }
}

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

public static byte[] getEncodedSubjectPublicKeyInfo(AlgorithmIdentifier algId, byte[] keyData)
{
  try
  {
    return getEncodedSubjectPublicKeyInfo(new SubjectPublicKeyInfo(algId, keyData));
  }
  catch (Exception e)
  {
    return null;
  }
}

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

public static byte[] getEncodedSubjectPublicKeyInfo(AlgorithmIdentifier algId, ASN1Encodable keyData)
{
  try
  {
    return getEncodedSubjectPublicKeyInfo(new SubjectPublicKeyInfo(algId, keyData));
  }
  catch (Exception e)
  {
    return null;
  }
}

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

public static SubjectPublicKeyInfo getInstance(
  Object  obj)
{
  if (obj instanceof SubjectPublicKeyInfo)
  {
    return (SubjectPublicKeyInfo)obj;
  }
  else if (obj != null)
  {
    return new SubjectPublicKeyInfo(ASN1Sequence.getInstance(obj));
  }
  return null;
}

代码示例来源:origin: com.google.code.jscep/jscep-api

private SubjectPublicKeyInfo getPublicKeyInfo() throws IOException {
  final ByteArrayInputStream bIn = new ByteArrayInputStream(keyPair.getPublic().getEncoded());
  final ASN1InputStream dIn = new ASN1InputStream(bIn);
  
  return new SubjectPublicKeyInfo((ASN1Sequence) dIn.readObject());
}

代码示例来源:origin: org.xipki.scep/scep-common

public static SubjectPublicKeyInfo createSubjectPublicKeyInfo(PublicKey publicKey)
  throws IOException {
 requireNonNull("publicKey", publicKey);
 if (publicKey instanceof java.security.interfaces.RSAPublicKey) {
  java.security.interfaces.RSAPublicKey rsaPubKey =
    (java.security.interfaces.RSAPublicKey) publicKey;
  return new SubjectPublicKeyInfo(ALGID_RSA,
    new RSAPublicKey(rsaPubKey.getModulus(), rsaPubKey.getPublicExponent()));
 } else {
  throw new IllegalArgumentException("unsupported public key " + publicKey);
 }
}

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

protected static MyKeypair generateRsaKeypair() throws Exception {
 KeyPairGenerator kpGen = KeyPairGenerator.getInstance("RSA");
 kpGen.initialize(2048);
 KeyPair kp = kpGen.generateKeyPair();
 RSAPublicKey pubKey = (RSAPublicKey) kp.getPublic();
 SubjectPublicKeyInfo subjectPublicKeyInfo = new SubjectPublicKeyInfo(
   new AlgorithmIdentifier(PKCSObjectIdentifiers.rsaEncryption, DERNull.INSTANCE),
   new org.bouncycastle.asn1.pkcs.RSAPublicKey(pubKey.getModulus(),
     pubKey.getPublicExponent()));
 return new MyKeypair(kp.getPrivate(), subjectPublicKeyInfo);
}

代码示例来源:origin: de.mhus.lib/mhu-lib-core

@SuppressWarnings("resource")
static AuthorityKeyIdentifier createAuthorityKeyId(
  PublicKey pub) 
  throws IOException
{
  ByteArrayInputStream bIn = new ByteArrayInputStream(pub.getEncoded());
  SubjectPublicKeyInfo info = new SubjectPublicKeyInfo(
    (ASN1Sequence)new ASN1InputStream(bIn).readObject());
  return new AuthorityKeyIdentifier(info);
}

代码示例来源:origin: de.mhus.lib/mhu-lib-core

@SuppressWarnings("resource")
static SubjectKeyIdentifier createSubjectKeyId(
  PublicKey pub) 
  throws IOException
{
  ByteArrayInputStream bIn = new ByteArrayInputStream(pub.getEncoded());
  SubjectPublicKeyInfo info = new SubjectPublicKeyInfo(
    (ASN1Sequence)new ASN1InputStream(bIn).readObject());
  return new SubjectKeyIdentifier(info);
}

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

private KeyPairWithSubjectPublicKeyInfo genRSAKeypair(final int keysize,
    final BigInteger publicExponent, final SecureRandom random) throws Exception {
  KeyPair kp = KeyUtil.generateRSAKeypair(keysize, publicExponent, random);
  java.security.interfaces.RSAPublicKey rsaPubKey =
      (java.security.interfaces.RSAPublicKey) kp.getPublic();
  SubjectPublicKeyInfo spki = new SubjectPublicKeyInfo(
      new AlgorithmIdentifier(PKCSObjectIdentifiers.rsaEncryption, DERNull.INSTANCE),
      new RSAPublicKey(rsaPubKey.getModulus(), rsaPubKey.getPublicExponent()));
  return new KeyPairWithSubjectPublicKeyInfo(kp, spki);
}

代码示例来源:origin: org.codeartisans.qipki/qipki-crypto

@Override
public AuthorityKeyIdentifier buildAuthorityKeyIdentifier( PublicKey publicKey )
{
  try {
    ByteArrayInputStream octets = new ByteArrayInputStream( publicKey.getEncoded() );
    SubjectPublicKeyInfo apki = new SubjectPublicKeyInfo( ( ASN1Sequence ) new ASN1InputStream( octets ).readObject() );
    return new AuthorityKeyIdentifier( apki );
  } catch ( IOException ex ) {
    throw new CryptoFailure( "Unable to build AuthorityKeyIdentifier", ex );
  }
}

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

private KeyPairWithSubjectPublicKeyInfo genRSAKeypair(int keysize,
  BigInteger publicExponent, SecureRandom random) throws Exception {
 KeyPair kp = KeyUtil.generateRSAKeypair(keysize, publicExponent, random);
 java.security.interfaces.RSAPublicKey rsaPubKey =
   (java.security.interfaces.RSAPublicKey) kp.getPublic();
 SubjectPublicKeyInfo spki = new SubjectPublicKeyInfo(
   new AlgorithmIdentifier(PKCSObjectIdentifiers.rsaEncryption, DERNull.INSTANCE),
   new RSAPublicKey(rsaPubKey.getModulus(), rsaPubKey.getPublicExponent()));
 return new KeyPairWithSubjectPublicKeyInfo(kp, spki);
}

代码示例来源:origin: org.codeartisans.qipki/qipki-crypto

@Override
public SubjectKeyIdentifier buildSubjectKeyIdentifier( PublicKey publicKey )
{
  try {
    ByteArrayInputStream octets = new ByteArrayInputStream( publicKey.getEncoded() );
    SubjectPublicKeyInfo spki = new SubjectPublicKeyInfo( ( ASN1Sequence ) new ASN1InputStream( octets ).readObject() );
    return new SubjectKeyIdentifier( spki );
  } catch ( IOException ex ) {
    throw new CryptoFailure( "Unable to build SubjectKeyIdentifier", ex );
  }
}

代码示例来源:origin: ZZMarquis/gmhelper

@Override
public byte[] getEncoded() {
  ASN1OctetString p = ASN1OctetString.getInstance(
    new X9ECPoint(getQ(), withCompression).toASN1Primitive());
  // stored curve is null if ImplicitlyCa
  SubjectPublicKeyInfo info = new SubjectPublicKeyInfo(
    new AlgorithmIdentifier(X9ObjectIdentifiers.id_ecPublicKey, ID_SM2_PUBKEY_PARAM),
    p.getOctets());
  return KeyUtil.getEncodedSubjectPublicKeyInfo(info);
}

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

public byte[] getEncoded()
{
  ASN1Encodable   params = ECUtils.getDomainParametersFromName(ecSpec, withCompression);
  ASN1OctetString p = ASN1OctetString.getInstance(new X9ECPoint(ecPublicKey.getQ(), withCompression).toASN1Primitive());
  // stored curve is null if ImplicitlyCa
  SubjectPublicKeyInfo info = new SubjectPublicKeyInfo(new AlgorithmIdentifier(X9ObjectIdentifiers.id_ecPublicKey, params), p.getOctets());
  return KeyUtil.getEncodedSubjectPublicKeyInfo(info);
}

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

public byte[] getEncoded()
{
  try
  {
    SubjectPublicKeyInfo    info = new SubjectPublicKeyInfo(new AlgorithmIdentifier(OIWObjectIdentifiers.elGamalAlgorithm, new ElGamalParameter(elSpec.getP(), elSpec.getG())), new ASN1Integer(y));
    return info.getEncoded(ASN1Encoding.DER);
  }
  catch (IOException e)
  {
    return null;
  }
}

相关文章