Java 类org.bouncycastle.asn1.x509.SubjectPublicKeyInfo 实例源码

项目:kafka-0.11.0.0-src-with-comment    文件:TestSslUtils.java   
public X509Certificate generate(String dn, KeyPair keyPair) throws CertificateException {
    try {
        Security.addProvider(new BouncyCastleProvider());
        AlgorithmIdentifier sigAlgId = new DefaultSignatureAlgorithmIdentifierFinder().find(algorithm);
        AlgorithmIdentifier digAlgId = new DefaultDigestAlgorithmIdentifierFinder().find(sigAlgId);
        AsymmetricKeyParameter privateKeyAsymKeyParam = PrivateKeyFactory.createKey(keyPair.getPrivate().getEncoded());
        SubjectPublicKeyInfo subPubKeyInfo = SubjectPublicKeyInfo.getInstance(keyPair.getPublic().getEncoded());
        ContentSigner sigGen = new BcRSAContentSignerBuilder(sigAlgId, digAlgId).build(privateKeyAsymKeyParam);
        X500Name name = new X500Name(dn);
        Date from = new Date();
        Date to = new Date(from.getTime() + days * 86400000L);
        BigInteger sn = new BigInteger(64, new SecureRandom());
        X509v3CertificateBuilder v3CertGen = new X509v3CertificateBuilder(name, sn, from, to, name, subPubKeyInfo);

        if (subjectAltName != null)
            v3CertGen.addExtension(Extension.subjectAlternativeName, false, subjectAltName);
        X509CertificateHolder certificateHolder = v3CertGen.build(sigGen);
        return new JcaX509CertificateConverter().setProvider("BC").getCertificate(certificateHolder);
    } catch (CertificateException ce) {
        throw ce;
    } catch (Exception e) {
        throw new CertificateException(e);
    }
}
项目:wakeup-qcloud-sdk    文件:DefaultQCloudClient.java   
@Override
public boolean verifyUserSig(String identifier, String sig)throws QCloudException {
    try {
        Security.addProvider(new BouncyCastleProvider());

        //DeBaseUrl64 urlSig to json
        Base64 decoder = new Base64();

        byte [] compressBytes = Base64Url.base64DecodeUrl(sig.getBytes(Charset.forName("UTF-8")));

        //Decompression
        Inflater decompression =  new Inflater();
        decompression.setInput(compressBytes, 0, compressBytes.length);
        byte [] decompressBytes = new byte [1024];
        int decompressLength = decompression.inflate(decompressBytes);
        decompression.end();

        String jsonString = new String(Arrays.copyOfRange(decompressBytes, 0, decompressLength));

        //Get TLS.Sig from json
        JSONObject jsonObject= JSON.parseObject(jsonString);
        String sigTLS = jsonObject.getString("TLS.sig");

        //debase64 TLS.Sig to get serailString
        byte[] signatureBytes = decoder.decode(sigTLS.getBytes(Charset.forName("UTF-8")));

        String strSdkAppid = jsonObject.getString("TLS.sdk_appid");
        String sigTime = jsonObject.getString("TLS.time");
        String sigExpire = jsonObject.getString("TLS.expire_after");

        if (!imConfig.getSdkAppId().equals(strSdkAppid))
        {
            return false;
        }

        if ( System.currentTimeMillis()/1000 - Long.parseLong(sigTime) > Long.parseLong(sigExpire)) {
            return false;
        }

        //Get Serial String from json
        String SerialString = 
            "TLS.appid_at_3rd:" + 0 + "\n" +
            "TLS.account_type:" + 0 + "\n" +
            "TLS.identifier:" + identifier + "\n" + 
            "TLS.sdk_appid:" + imConfig.getSdkAppId() + "\n" + 
            "TLS.time:" + sigTime + "\n" + 
            "TLS.expire_after:" + sigExpire + "\n";

        Reader reader = new CharArrayReader(imConfig.getPublicKey().toCharArray());
        PEMParser  parser = new PEMParser(reader);
        JcaPEMKeyConverter converter = new JcaPEMKeyConverter();
        Object obj = parser.readObject();
        parser.close();
        PublicKey pubKeyStruct  = converter.getPublicKey((SubjectPublicKeyInfo) obj);

        Signature signature = Signature.getInstance("SHA256withECDSA","BC");
        signature.initVerify(pubKeyStruct);
        signature.update(SerialString.getBytes(Charset.forName("UTF-8")));
        return signature.verify(signatureBytes);
    }catch (Exception e) {
        throw new QCloudException(e);
    }
}
项目:ipack    文件:X509v1CertificateBuilder.java   
/**
 * Create a builder for a version 1 certificate.
 *
 * @param issuer the certificate issuer
 * @param serial the certificate serial number
 * @param notBefore the date before which the certificate is not valid
 * @param notAfter the date after which the certificate is not valid
 * @param subject the certificate subject
 * @param publicKeyInfo the info structure for the public key to be associated with this certificate.
 */
public X509v1CertificateBuilder(X500Name issuer, BigInteger serial, Date notBefore, Date notAfter, X500Name subject, SubjectPublicKeyInfo publicKeyInfo)
{
    if (issuer == null)
    {
        throw new IllegalArgumentException("issuer must not be null");
    }

    if (publicKeyInfo == null)
    {
        throw new IllegalArgumentException("publicKeyInfo must not be null");
    }

    tbsGen = new V1TBSCertificateGenerator();
    tbsGen.setSerialNumber(new ASN1Integer(serial));
    tbsGen.setIssuer(issuer);
    tbsGen.setStartDate(new Time(notBefore));
    tbsGen.setEndDate(new Time(notAfter));
    tbsGen.setSubject(subject);
    tbsGen.setSubjectPublicKeyInfo(publicKeyInfo);
}
项目:ipack    文件:X509ExtensionUtils.java   
private byte[] calculateIdentifier(SubjectPublicKeyInfo publicKeyInfo)
{
    byte[] bytes = publicKeyInfo.getPublicKeyData().getBytes();

    OutputStream cOut = calculator.getOutputStream();

    try
    {
        cOut.write(bytes);

        cOut.close();
    }
    catch (IOException e)
    {   // it's hard to imagine this happening, but yes it does!
        throw new CertRuntimeException("unable to calculate identifier: " + e.getMessage(), e);
    }

    return calculator.getDigest();
}
项目:ipack    文件:JcaPEMKeyConverter.java   
public PublicKey getPublicKey(SubjectPublicKeyInfo publicKeyInfo)
    throws PEMException
{
    try
    {
        String algorithm =  publicKeyInfo.getAlgorithm().getAlgorithm().getId();

        if (X9ObjectIdentifiers.id_ecPublicKey.getId().equals(algorithm))
        {
            algorithm = "ECDSA";
        }

        KeyFactory keyFactory = helper.createKeyFactory(algorithm);

        return keyFactory.generatePublic(new X509EncodedKeySpec(publicKeyInfo.getEncoded()));
    }
    catch (Exception e)
    {
        throw new PEMException("unable to convert key pair: " + e.getMessage(), e);
    }
}
项目:ipack    文件:JDKDSAPublicKey.java   
public byte[] getEncoded()
{
    try
    {
        if (dsaSpec == null)
        {
            return new SubjectPublicKeyInfo(new AlgorithmIdentifier(X9ObjectIdentifiers.id_dsa), new DERInteger(y)).getEncoded(ASN1Encoding.DER);
        }

        return new SubjectPublicKeyInfo(new AlgorithmIdentifier(X9ObjectIdentifiers.id_dsa, new DSAParameter(dsaSpec.getP(), dsaSpec.getQ(), dsaSpec.getG())), new DERInteger(y)).getEncoded(ASN1Encoding.DER);
    }
    catch (IOException e)
    {
        return null;
    }
}
项目:ipack    文件:RainbowKeyFactorySpi.java   
/**
 * Converts, if possible, a key specification into a
 * {@link BCRainbowPublicKey}. Currently, the following key specifications are
 * supported:{@link X509EncodedKeySpec}.
 * <p/>
 * <p/>
 * <p/>
 * The ASN.1 definition of a public key's structure is
 * <p/>
 * <pre>
 *    RainbowPublicKey ::= SEQUENCE {
 *      oid            OBJECT IDENTIFIER        -- OID identifying the algorithm
 *      docLength      Integer                  -- length of signable msg
 *      coeffquadratic SEQUENCE OF OCTET STRING -- quadratic (mixed) coefficients
 *      coeffsingular  SEQUENCE OF OCTET STRING -- singular coefficients
 *      coeffscalar       OCTET STRING             -- scalar coefficients
 *       }
 * </pre>
 * <p/>
 * <p/>
 *
 * @param keySpec the key specification
 * @return the Rainbow public key
 * @throws InvalidKeySpecException if the KeySpec is not supported.
 */
public PublicKey engineGeneratePublic(KeySpec keySpec)
    throws InvalidKeySpecException
{
    if (keySpec instanceof RainbowPublicKeySpec)
    {
        return new BCRainbowPublicKey((RainbowPublicKeySpec)keySpec);
    }
    else if (keySpec instanceof X509EncodedKeySpec)
    {
        // get the DER-encoded Key according to X.509 from the spec
        byte[] encKey = ((X509EncodedKeySpec)keySpec).getEncoded();

        // decode the SubjectPublicKeyInfo data structure to the pki object
        try
        {
            return generatePublic(SubjectPublicKeyInfo.getInstance(encKey));
        }
        catch (Exception e)
        {
            throw new InvalidKeySpecException(e.toString());
        }
    }

    throw new InvalidKeySpecException("Unknown key specification: " + keySpec + ".");
}
项目:ipack    文件:TlsServerProtocol.java   
protected void receiveCertificateVerifyMessage(ByteArrayInputStream buf)
    throws IOException
{

    byte[] clientCertificateSignature = TlsUtils.readOpaque16(buf);

    assertEmpty(buf);

    // Verify the CertificateVerify message contains a correct signature.
    try
    {
        TlsSigner tlsSigner = TlsUtils.createTlsSigner(this.clientCertificateType);
        tlsSigner.init(getContext());

        org.bouncycastle.asn1.x509.Certificate x509Cert = this.clientCertificate.getCertificateAt(0);
        SubjectPublicKeyInfo keyInfo = x509Cert.getSubjectPublicKeyInfo();
        AsymmetricKeyParameter publicKey = PublicKeyFactory.createKey(keyInfo);

        tlsSigner.verifyRawSignature(clientCertificateSignature, publicKey, this.certificateVerifyHash);
    }
    catch (Exception e)
    {
        throw new TlsFatalAlert(AlertDescription.decrypt_error);
    }
}
项目:ipack    文件:KeyAgreeRecipientInformation.java   
private SubjectPublicKeyInfo getSenderPublicKeyInfo(AlgorithmIdentifier recKeyAlgId,
    OriginatorIdentifierOrKey originator)
    throws CMSException, IOException
{
    OriginatorPublicKey opk = originator.getOriginatorKey();
    if (opk != null)
    {
        return getPublicKeyInfoFromOriginatorPublicKey(recKeyAlgId, opk);
    }

    OriginatorId origID;

    IssuerAndSerialNumber iAndSN = originator.getIssuerAndSerialNumber();
    if (iAndSN != null)
    {
        origID = new OriginatorId(iAndSN.getName(), iAndSN.getSerialNumber().getValue());
    }
    else
    {
        SubjectKeyIdentifier ski = originator.getSubjectKeyIdentifier();

        origID = new OriginatorId(ski.getKeyIdentifier());
    }

    return getPublicKeyInfoFromOriginatorId(origID);
}
项目:xtf    文件:XTFKeyStore.java   
public void addSelfSignedCertificate(String certificateAlias, String dn, String password) {
    try {
        KeyPair keys = generateKeyPair();

        Calendar start = Calendar.getInstance();
        Calendar expiry = Calendar.getInstance();
        expiry.add(Calendar.YEAR, 1);
        X500Name name = new X500Name(dn);
        X509v3CertificateBuilder certificateBuilder = new X509v3CertificateBuilder(name, BigInteger.ONE,
                start.getTime(), expiry.getTime(), name, SubjectPublicKeyInfo.getInstance(keys.getPublic().getEncoded()));
        ContentSigner signer = new JcaContentSignerBuilder("SHA1WithRSA").setProvider(new BouncyCastleProvider()).build(keys.getPrivate());
        X509CertificateHolder holder = certificateBuilder.build(signer);
        Certificate cert = new JcaX509CertificateConverter().setProvider(new BouncyCastleProvider()).getCertificate(holder);

        Entry entry = new PrivateKeyEntry(keys.getPrivate(), new Certificate[]{ cert });
        keystore.setEntry(certificateAlias, entry, new PasswordProtection(password.toCharArray()));
    } catch (GeneralSecurityException | OperatorCreationException ex) {
        throw new RuntimeException("Unable to generate self-signed certificate", ex);
    }
}
项目:ipack    文件:BaseKeyFactorySpi.java   
protected PublicKey engineGeneratePublic(
    KeySpec keySpec)
    throws InvalidKeySpecException
{
    if (keySpec instanceof X509EncodedKeySpec)
    {
        try
        {
            return generatePublic(SubjectPublicKeyInfo.getInstance(((X509EncodedKeySpec)keySpec).getEncoded()));
        }
        catch (Exception e)
        {
            throw new InvalidKeySpecException("encoded key spec not recognised");
        }
    }
    else
    {
        throw new InvalidKeySpecException("key spec not recognised");
    }
}
项目:ipack    文件:SignatureSpi.java   
protected void engineInitVerify(
    PublicKey   publicKey)
    throws InvalidKeyException
{
    CipherParameters    param;

    if (publicKey instanceof ECPublicKey)
    {
        param = ECUtil.generatePublicKeyParameter(publicKey);
    }
    else if (publicKey instanceof GOST3410Key)
    {
        param = GOST3410Util.generatePublicKeyParameter(publicKey);
    }
    else
    {
        try
        {
            byte[]  bytes = publicKey.getEncoded();

            publicKey = BouncyCastleProvider.getPublicKey(SubjectPublicKeyInfo.getInstance(bytes));

            if (publicKey instanceof ECPublicKey)
            {
                param = ECUtil.generatePublicKeyParameter(publicKey);
            }
            else
            {
                throw new InvalidKeyException("can't recognise key type in DSA based signer");
            }
        }
        catch (Exception e)
        {
            throw new InvalidKeyException("can't recognise key type in DSA based signer");
        }
    }

    digest.reset();
    signer.init(false, param);
}
项目:ipack    文件:KeyFactorySpi.java   
public PublicKey generatePublic(SubjectPublicKeyInfo keyInfo)
    throws IOException
{
    ASN1ObjectIdentifier algOid = keyInfo.getAlgorithm().getAlgorithm();

    if (algOid.equals(PKCSObjectIdentifiers.dhKeyAgreement))
    {
        return new BCDHPublicKey(keyInfo);
    }
    else if (algOid.equals(X9ObjectIdentifiers.dhpublicnumber))
    {
        return new BCDHPublicKey(keyInfo);
    }
    else
    {
        throw new IOException("algorithm identifier " + algOid + " in key not recognised");
    }
}
项目:ipack    文件:JceKeyAgreeAuthenticatedRecipient.java   
public RecipientOperator getRecipientOperator(AlgorithmIdentifier keyEncryptionAlgorithm, final AlgorithmIdentifier contentMacAlgorithm, SubjectPublicKeyInfo senderPublicKey, ASN1OctetString userKeyingMaterial, byte[] encryptedContentKey)
    throws CMSException
{
    final Key secretKey = extractSecretKey(keyEncryptionAlgorithm, contentMacAlgorithm, senderPublicKey, userKeyingMaterial, encryptedContentKey);

    final Mac dataMac = contentHelper.createContentMac(secretKey, contentMacAlgorithm);

    return new RecipientOperator(new MacCalculator()
    {
        public AlgorithmIdentifier getAlgorithmIdentifier()
        {
            return contentMacAlgorithm;
        }

        public GenericKey getKey()
        {
            return new JceGenericKey(contentMacAlgorithm, secretKey);
        }

        public OutputStream getOutputStream()
        {
            return new MacOutputStream(dataMac);
        }

        public byte[] getMac()
        {
            return dataMac.doFinal();
        }
    });
}
项目:ipack    文件:SubjectKeyIdentifierStructure.java   
private static ASN1OctetString fromPublicKey(
    PublicKey pubKey)
    throws InvalidKeyException
{
    try
    {
        SubjectPublicKeyInfo info = SubjectPublicKeyInfo.getInstance(pubKey.getEncoded());

        return (ASN1OctetString)(new SubjectKeyIdentifier(info).toASN1Object());
    }
    catch (Exception e)
    {
        throw new InvalidKeyException("Exception extracting key details: " + e.toString());
    }
}
项目:ipack    文件:BCECPrivateKey.java   
private DERBitString getPublicKeyDetails(BCECPublicKey pub)
{
    try
    {
        SubjectPublicKeyInfo info = SubjectPublicKeyInfo.getInstance(ASN1Primitive.fromByteArray(pub.getEncoded()));

        return info.getPublicKeyData();
    }
    catch (IOException e)
    {   // should never happen
        return null;
    }
}
项目:ipack    文件:CertificateID.java   
private static CertID createCertID(AlgorithmIdentifier hashAlg, X509Certificate issuerCert,
    ASN1Integer serialNumber, String provider)
    throws OCSPException
{
    try
    {
        MessageDigest digest = OCSPUtil.createDigestInstance(hashAlg.getAlgorithm() .getId(),
            provider);

        X509Principal issuerName = PrincipalUtil.getSubjectX509Principal(issuerCert);

        digest.update(issuerName.getEncoded());

        ASN1OctetString issuerNameHash = new DEROctetString(digest.digest());
        PublicKey issuerKey = issuerCert.getPublicKey();

        ASN1InputStream aIn = new ASN1InputStream(issuerKey.getEncoded());
        SubjectPublicKeyInfo info = SubjectPublicKeyInfo.getInstance(aIn.readObject());

        digest.update(info.getPublicKeyData().getBytes());

        ASN1OctetString issuerKeyHash = new DEROctetString(digest.digest());

        return new CertID(hashAlg, issuerNameHash, issuerKeyHash, serialNumber);
    }
    catch (Exception e)
    {
        throw new OCSPException("problem creating ID: " + e, e);
    }
}
项目:ipack    文件:X509V3CertificateGenerator.java   
public void setPublicKey(
    PublicKey       key)
    throws IllegalArgumentException
{
    try
    {
        tbsGen.setSubjectPublicKeyInfo(
                   SubjectPublicKeyInfo.getInstance(new ASN1InputStream(key.getEncoded()).readObject()));
    }
    catch (Exception e)
    {
        throw new IllegalArgumentException("unable to process key - " + e.toString());
    }
}
项目:ipack    文件:X509ExtensionUtils.java   
/**
 * Return a RFC 3280 type 2 key identifier. As in:
 * <pre>
 * (2) The keyIdentifier is composed of a four bit type field with
 * the value 0100 followed by the least significant 60 bits of the
 * SHA-1 hash of the value of the BIT STRING subjectPublicKey.
 * </pre>
 * @param publicKeyInfo the key info object containing the subjectPublicKey field.
 * @return the key identifier.
 */
public SubjectKeyIdentifier createTruncatedSubjectKeyIdentifier(SubjectPublicKeyInfo publicKeyInfo)
{
    byte[] digest = calculateIdentifier(publicKeyInfo);
    byte[] id = new byte[8];

    System.arraycopy(digest, digest.length - 8, id, 0, id.length);

    id[0] &= 0x0f;
    id[0] |= 0x40;

    return new SubjectKeyIdentifier(id);
}
项目:xitk    文件:P12KeyGenerator.java   
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);
}
项目:ipack    文件:CertificateRequestMessageBuilder.java   
public CertificateRequestMessageBuilder setPublicKey(SubjectPublicKeyInfo publicKey)
{
    if (publicKey != null)
    {
        templateBuilder.setPublicKey(publicKey);
    }

    return this;
}
项目:ipack    文件:CRMFHelper.java   
PublicKey toPublicKey(SubjectPublicKeyInfo subjectPublicKeyInfo)
    throws CRMFException
{
    try
    {
        X509EncodedKeySpec xspec = new X509EncodedKeySpec(subjectPublicKeyInfo.getEncoded());
        AlgorithmIdentifier keyAlg = subjectPublicKeyInfo.getAlgorithm();

        return createKeyFactory(keyAlg.getAlgorithm()).generatePublic(xspec);
    }
    catch (Exception e)
    {
        throw new CRMFException("invalid key: " + e.getMessage(), e);
    }
}
项目:ipack    文件:JcaCertificateRequestMessage.java   
public PublicKey getPublicKey()
    throws CRMFException
{
    SubjectPublicKeyInfo subjectPublicKeyInfo = getCertTemplate().getPublicKey();

    if (subjectPublicKeyInfo != null)
    {
        return helper.toPublicKey(subjectPublicKeyInfo);
    }

    return null;
}
项目:ipack    文件:PKCS12KeyStoreSpi.java   
private SubjectKeyIdentifier createSubjectKeyId(
    PublicKey pubKey)
{
    try
    {
        SubjectPublicKeyInfo info = new SubjectPublicKeyInfo(
            (ASN1Sequence)ASN1Primitive.fromByteArray(pubKey.getEncoded()));

        return new SubjectKeyIdentifier(info);
    }
    catch (Exception e)
    {
        throw new RuntimeException("error creating key");
    }
}
项目:xitk    文件:SecurityFactoryImpl.java   
@Override
public PublicKey generatePublicKey(SubjectPublicKeyInfo subjectPublicKeyInfo)
        throws InvalidKeyException {
    try {
        return KeyUtil.generatePublicKey(subjectPublicKeyInfo);
    } catch (NoSuchAlgorithmException | InvalidKeySpecException ex) {
        throw new InvalidKeyException(ex.getMessage(), ex);
    }
}
项目:ipack    文件:X509v3CertificateBuilder.java   
/**
 * Create a builder for a version 3 certificate.
 *
 * @param issuer the certificate issuer
 * @param serial the certificate serial number
 * @param notBefore the date before which the certificate is not valid
 * @param notAfter the date after which the certificate is not valid
 * @param subject the certificate subject
 * @param publicKeyInfo the info structure for the public key to be associated with this certificate.
 */
public X509v3CertificateBuilder(X500Name issuer, BigInteger serial, Date notBefore, Date notAfter, X500Name subject, SubjectPublicKeyInfo publicKeyInfo)
{
    tbsGen = new V3TBSCertificateGenerator();
    tbsGen.setSerialNumber(new ASN1Integer(serial));
    tbsGen.setIssuer(issuer);
    tbsGen.setStartDate(new Time(notBefore));
    tbsGen.setEndDate(new Time(notAfter));
    tbsGen.setSubject(subject);
    tbsGen.setSubjectPublicKeyInfo(publicKeyInfo);

    extGenerator = new ExtensionsGenerator();
}
项目:ipack    文件:CertificateID.java   
private static CertID createCertID(DigestCalculator digCalc, X509CertificateHolder issuerCert, ASN1Integer serialNumber)
    throws OCSPException
{
    try
    {
        OutputStream dgOut = digCalc.getOutputStream();

        dgOut.write(issuerCert.toASN1Structure().getSubject().getEncoded(ASN1Encoding.DER));
        dgOut.close();

        ASN1OctetString issuerNameHash = new DEROctetString(digCalc.getDigest());

        SubjectPublicKeyInfo info = issuerCert.getSubjectPublicKeyInfo();

        dgOut = digCalc.getOutputStream();

        dgOut.write(info.getPublicKeyData().getBytes());
        dgOut.close();

        ASN1OctetString issuerKeyHash = new DEROctetString(digCalc.getDigest());

        return new CertID(digCalc.getAlgorithmIdentifier(), issuerNameHash, issuerKeyHash, serialNumber);
    }
    catch (Exception e)
    {
        throw new OCSPException("problem creating ID: " + e, e);
    }
}
项目:ipack    文件:JceKeyAgreeRecipientInfoGenerator.java   
protected ASN1Encodable getUserKeyingMaterial(AlgorithmIdentifier keyAgreeAlg)
    throws CMSException
{
    init(keyAgreeAlg.getAlgorithm());

    if (ephemeralKP != null)
    {
        return new MQVuserKeyingMaterial(
                    createOriginatorPublicKey(SubjectPublicKeyInfo.getInstance(ephemeralKP.getPublic().getEncoded())), null);
    }

    return null;
}
项目:ipack    文件:BasicOCSPRespBuilder.java   
/**
 * construct with the responderID to be the SHA-1 keyHash of the passed in public key.
 *
 * @param key the key info of the responder public key.
 * @param digCalc  a SHA-1 digest calculator
 */
public BasicOCSPRespBuilder(
    SubjectPublicKeyInfo key,
    DigestCalculator     digCalc)
    throws OCSPException
{
    this.responderID = new RespID(key, digCalc);
}
项目:ipack    文件:JCERSAPublicKey.java   
JCERSAPublicKey(
    SubjectPublicKeyInfo    info)
{
    try
    {
        RSAPublicKeyStructure   pubKey = new RSAPublicKeyStructure((ASN1Sequence)info.parsePublicKey());

        this.modulus = pubKey.getModulus();
        this.publicExponent = pubKey.getPublicExponent();
    }
    catch (IOException e)
    {
        throw new IllegalArgumentException("invalid info structure in RSA public key");
    }
}
项目:ipack    文件:JCEECPrivateKey.java   
private DERBitString getPublicKeyDetails(JCEECPublicKey   pub)
{
    try
    {
        SubjectPublicKeyInfo info = SubjectPublicKeyInfo.getInstance(ASN1Primitive.fromByteArray(pub.getEncoded()));

        return info.getPublicKeyData();
    }
    catch (IOException e)
    {   // should never happen
        return null;
    }
}
项目:ipack    文件:BouncyCastleProvider.java   
public static PublicKey getPublicKey(SubjectPublicKeyInfo publicKeyInfo)
    throws IOException
{
    AsymmetricKeyInfoConverter converter = (AsymmetricKeyInfoConverter)keyInfoConverters.get(publicKeyInfo.getAlgorithm().getAlgorithm());

    if (converter == null)
    {
        return null;
    }

    return converter.generatePublic(publicKeyInfo);
}
项目:dremio-oss    文件:ElasticsearchCluster.java   
private static Certificate genSelfSignedCert(KeyPair keyPair, String signAlgo) throws CertificateException {
  X500Name issuer = new X500Name("CN=localhost, OU=test, O=Dremio, L=Mountain View, ST=CA, C=US");
  X500Name subject = issuer; // self signed
  BigInteger serial = BigInteger.valueOf(new Random().nextInt());
  Date notBefore = new Date(System.currentTimeMillis() - (24 * 3600 * 1000));
  Date notAfter = new Date(System.currentTimeMillis() + (24 * 3600 * 1000));
  SubjectPublicKeyInfo pubkeyInfo = SubjectPublicKeyInfo.getInstance(keyPair.getPublic().getEncoded());
  X509v3CertificateBuilder certBuilder = new X509v3CertificateBuilder(issuer, serial, notBefore, notAfter, subject, pubkeyInfo);
  ContentSigner signer = newSigner(keyPair.getPrivate(), signAlgo);
  X509CertificateHolder certHolder = certBuilder.build(signer);

  Certificate cert = new JcaX509CertificateConverter().getCertificate(certHolder);
  return cert;
}
项目:ipack    文件:JCEECPublicKey.java   
private void readObject(
    ObjectInputStream in)
    throws IOException, ClassNotFoundException
{
    byte[] enc = (byte[])in.readObject();

    populateFromPubKeyInfo(SubjectPublicKeyInfo.getInstance(ASN1Primitive.fromByteArray(enc)));

    this.algorithm = (String)in.readObject();
    this.withCompression = in.readBoolean();
}
项目:NBANDROID-V2    文件:ApkUtils.java   
private static Pair<PrivateKey, X509Certificate> generateKeyAndCertificate(String asymmetric, String sign, int validityYears, String dn) throws NoSuchAlgorithmException, OperatorCreationException, CertificateException {
    Preconditions.checkArgument(validityYears > 0, "validityYears <= 0");
    KeyPair keyPair = KeyPairGenerator.getInstance(asymmetric).generateKeyPair();
    Date notBefore = new Date(System.currentTimeMillis());
    Date notAfter = new Date(System.currentTimeMillis() + validityYears * 31536000000l);
    X500Name issuer = new X500Name(new X500Principal(dn).getName());
    SubjectPublicKeyInfo publicKeyInfo = SubjectPublicKeyInfo.getInstance(keyPair.getPublic().getEncoded());
    X509v1CertificateBuilder builder = new X509v1CertificateBuilder(issuer, BigInteger.ONE, notBefore, notAfter, issuer, publicKeyInfo);
    ContentSigner signer = new JcaContentSignerBuilder(sign).setProvider(new BouncyCastleProvider()).build(keyPair.getPrivate());
    X509CertificateHolder holder = builder.build(signer);
    JcaX509CertificateConverter converter = new JcaX509CertificateConverter().setProvider(new BouncyCastleProvider());
    X509Certificate certificate = converter.getCertificate(holder);
    return Pair.of(keyPair.getPrivate(), certificate);
}
项目:ipack    文件:McElieceCCA2KeyFactorySpi.java   
public PublicKey generatePublic(SubjectPublicKeyInfo pki)
    throws InvalidKeySpecException
{
    // get the inner type inside the BIT STRING
    try
    {
        ASN1Primitive innerType = pki.parsePublicKey();
        McElieceCCA2PublicKey key = McElieceCCA2PublicKey.getInstance((ASN1Sequence)innerType);
        return new BCMcElieceCCA2PublicKey(key.getOID().getId(), key.getN(), key.getT(), key.getG());
    }
    catch (IOException cce)
    {
        throw new InvalidKeySpecException("Unable to decode X509EncodedKeySpec");
    }
}
项目:ipack    文件:McElieceKeyFactorySpi.java   
public PublicKey generatePublic(SubjectPublicKeyInfo pki)
    throws InvalidKeySpecException
{
    // get the inner type inside the BIT STRING
    try
    {
        ASN1Primitive innerType = pki.parsePublicKey();
        McEliecePublicKey key = McEliecePublicKey.getInstance(innerType);
        return new BCMcEliecePublicKey(key.getOID().getId(), key.getN(), key.getT(), key.getG());
    }
    catch (IOException cce)
    {
        throw new InvalidKeySpecException("Unable to decode X509EncodedKeySpec");
    }
}
项目:ipack    文件:BouncyCastlePQCProvider.java   
public static PublicKey getPublicKey(SubjectPublicKeyInfo publicKeyInfo)
    throws IOException
{
    AsymmetricKeyInfoConverter converter = (AsymmetricKeyInfoConverter)keyInfoConverters.get(publicKeyInfo.getAlgorithm().getAlgorithm());

    if (converter == null)
    {
        return null;
    }

    return converter.generatePublic(publicKeyInfo);
}
项目:ipack    文件:KeyUtil.java   
public static byte[] getEncodedSubjectPublicKeyInfo(AlgorithmIdentifier algId, ASN1Encodable keyData)
{
    try
    {
        return getEncodedSubjectPublicKeyInfo(new SubjectPublicKeyInfo(algId, keyData));
    }
    catch (Exception e)
    {
        return null;
    }
}
项目:ipack    文件:KeyUtil.java   
public static byte[] getEncodedSubjectPublicKeyInfo(AlgorithmIdentifier algId, byte[] keyData)
{
    try
    {
        return getEncodedSubjectPublicKeyInfo(new SubjectPublicKeyInfo(algId, keyData));
    }
    catch (Exception e)
    {
        return null;
    }
}