当前位置: 首页>>代码示例>>Java>>正文


Java RSAPublicKey类代码示例

本文整理汇总了Java中org.bouncycastle.asn1.pkcs.RSAPublicKey的典型用法代码示例。如果您正苦于以下问题:Java RSAPublicKey类的具体用法?Java RSAPublicKey怎么用?Java RSAPublicKey使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


RSAPublicKey类属于org.bouncycastle.asn1.pkcs包,在下文中一共展示了RSAPublicKey类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: makeV1Certificate

import org.bouncycastle.asn1.pkcs.RSAPublicKey; //导入依赖的package包/类
public static X509CertificateHolder makeV1Certificate(AsymmetricCipherKeyPair subKP, String _subDN, AsymmetricCipherKeyPair issKP, String _issDN)
    throws IOException, OperatorCreationException
{
    RSAKeyParameters lwPubKey = (RSAKeyParameters)subKP.getPublic();

    X509v1CertificateBuilder v1CertGen = new X509v1CertificateBuilder(
        new X500Name(_issDN),
        allocateSerialNumber(),
        new Date(System.currentTimeMillis()),
        new Date(System.currentTimeMillis() + (1000L * 60 * 60 * 24 * 100)),
        new X500Name(_subDN),
        new SubjectPublicKeyInfo(new AlgorithmIdentifier(PKCSObjectIdentifiers.rsaEncryption, DERNull.INSTANCE), new RSAPublicKey(lwPubKey.getModulus(), lwPubKey.getExponent()))
    );

    AlgorithmIdentifier sigAlgId = new DefaultSignatureAlgorithmIdentifierFinder().find("SHA1WithRSAEncryption");
    AlgorithmIdentifier digAlgId = new DefaultDigestAlgorithmIdentifierFinder().find(sigAlgId);

    ContentSigner sigGen = new BcRSAContentSignerBuilder(sigAlgId, digAlgId).build((AsymmetricKeyParameter)issKP.getPrivate());


    return v1CertGen.build(sigGen);
}
 
开发者ID:ttt43ttt,项目名称:gwt-crypto,代码行数:23,代码来源:CMSTestUtil.java

示例2: makeCertificate

import org.bouncycastle.asn1.pkcs.RSAPublicKey; //导入依赖的package包/类
public static X509CertificateHolder makeCertificate(AsymmetricCipherKeyPair subKP, String _subDN, AsymmetricCipherKeyPair issKP, String _issDN, boolean _ca)
    throws IOException, OperatorCreationException
{
    RSAKeyParameters lwPubKey = (RSAKeyParameters)subKP.getPublic();

    X509v3CertificateBuilder v3CertGen = new X509v3CertificateBuilder(
        new X500Name(_issDN),
        allocateSerialNumber(),
        new Date(System.currentTimeMillis()),
        new Date(System.currentTimeMillis() + (1000L * 60 * 60 * 24 * 100)),
        new X500Name(_subDN),
        new SubjectPublicKeyInfo(new AlgorithmIdentifier(PKCSObjectIdentifiers.rsaEncryption, DERNull.INSTANCE), new RSAPublicKey(lwPubKey.getModulus(), lwPubKey.getExponent()))
    );

    AlgorithmIdentifier sigAlgId = new DefaultSignatureAlgorithmIdentifierFinder().find("SHA1WithRSAEncryption");
    AlgorithmIdentifier digAlgId = new DefaultDigestAlgorithmIdentifierFinder().find(sigAlgId);

    ContentSigner sigGen = new BcRSAContentSignerBuilder(sigAlgId, digAlgId).build((AsymmetricKeyParameter)issKP.getPrivate());

    v3CertGen.addExtension(
        X509Extension.basicConstraints,
        false,
        new BasicConstraints(_ca));

    return v3CertGen.build(sigGen);
}
 
开发者ID:ttt43ttt,项目名称:gwt-crypto,代码行数:27,代码来源:CMSTestUtil.java

示例3: parsePublicKey

import org.bouncycastle.asn1.pkcs.RSAPublicKey; //导入依赖的package包/类
public static java.security.interfaces.RSAPublicKey parsePublicKey(String key) {
    Matcher m = SSH_PUB_KEY.matcher(key);
    if (m.matches()) {
        String alg = m.group(1);
        String encKey = m.group(2);
        if (!"rsa".equalsIgnoreCase(alg)) {
            throw new IllegalArgumentException("Only RSA is currently supported, but algorithm was " + alg);
        } else {
            return parseSSHPublicKey(encKey);
        }
    } else if (!key.startsWith(BEGIN)) {
        return parseSSHPublicKey(key);
    } else {
        KeyPair kp = parseKeyPair(key);
        if (kp.getPublic() == null) {
            throw new IllegalArgumentException("Key data does not contain a public key");
        } else {
            return (java.security.interfaces.RSAPublicKey) kp.getPublic();
        }
    }
}
 
开发者ID:baomidou,项目名称:kisso,代码行数:22,代码来源:RsaKeyHelper.java

示例4: parseSSHPublicKey

import org.bouncycastle.asn1.pkcs.RSAPublicKey; //导入依赖的package包/类
private static java.security.interfaces.RSAPublicKey parseSSHPublicKey(String encKey) {
    byte[] PREFIX = new byte[]{0, 0, 0, 7, 115, 115, 104, 45, 114, 115, 97};
    ByteArrayInputStream in = new ByteArrayInputStream(Codecs.b64Decode(Codecs.utf8Encode(encKey)));
    byte[] prefix = new byte[11];

    try {
        if (in.read(prefix) == 11 && Arrays.equals(PREFIX, prefix)) {
            BigInteger e = new BigInteger(readBigInteger(in));
            BigInteger n = new BigInteger(readBigInteger(in));
            return createPublicKey(n, e);
        } else {
            throw new IllegalArgumentException("SSH key prefix not found");
        }
    } catch (IOException var6) {
        throw new RuntimeException(var6);
    }
}
 
开发者ID:baomidou,项目名称:kisso,代码行数:18,代码来源:RsaKeyHelper.java

示例5: extractBinaryRSAKey

import org.bouncycastle.asn1.pkcs.RSAPublicKey; //导入依赖的package包/类
/**
 * makes RSA public key from bin byte array.
 *
 * @param b byte array that contains the key
 * @return
 * @see JCERSAPublicKey
 */
public static RSAPublicKey extractBinaryRSAKey(final byte[] b) {
    RSAPublicKey theKey;

    try {
        final ASN1InputStream ais = new ASN1InputStream(b);
        final Object asnObject = ais.readObject();
        final ASN1Sequence sequence = (ASN1Sequence) asnObject;
        final RSAPublicKeyStructure tempKey = new RSAPublicKeyStructure(sequence);
        theKey = getRSAPublicKey(tempKey.getModulus(), tempKey.getPublicExponent());
        ais.close();
    } catch (final IOException e) {
        logger.warn("Caught exception:" + e.getMessage());
        theKey = null;
    }

    return theKey;
}
 
开发者ID:rovemonteux,项目名称:silvertunnel-monteux,代码行数:25,代码来源:Encryption.java

示例6: createNewRSAKeyPair

import org.bouncycastle.asn1.pkcs.RSAPublicKey; //导入依赖的package包/类
/**
 * Create a fresh RSA key pair.
 *
 * @return a new RSAKeyPair
 */
public static RSAKeyPair createNewRSAKeyPair() {
    try {
        // Generate a 1024-bit RSA key pair
        final KeyPairGenerator keyGen = KeyPairGenerator.getInstance("RSA");
        keyGen.initialize(KEY_STRENGTH);
        final KeyPair keypair = keyGen.genKeyPair();
        final RSAPrivateCrtKey privateKey = (RSAPrivateCrtKey) keypair.getPrivate();
        final RSAPublicKey publicKey = (RSAPublicKey) keypair.getPublic();

        return new RSAKeyPair(publicKey, privateKey);

    } catch (final NoSuchAlgorithmException e) {
        logger.error("Could not create new key pair", e);
        throw new RuntimeException(e);
    }
}
 
开发者ID:rovemonteux,项目名称:silvertunnel-monteux,代码行数:22,代码来源:Encryption.java

示例7: encodePublicKey

import org.bouncycastle.asn1.pkcs.RSAPublicKey; //导入依赖的package包/类
/**
 * Encode (serialise) a public key in order to store it or transport it over a network.
 * @param publicKey the public key to be encoded; must not be <code>null</code>.
 * @return the encoded (serialised) form of the public key. Can be passed to {@link #decodePublicKey(byte[])} to
 * reverse this method.
 * @see #decodePublicKey(byte[])
 * @see #encodePrivateKey(CipherParameters)
 */
public byte[] encodePublicKey(final CipherParameters publicKey)
{
	if (publicKey == null)
		throw new IllegalArgumentException("publicKey == null");

	// TODO use a class-based map or similar registry!
	try {
		if (publicKey instanceof RSAKeyParameters) {
			final RSAKeyParameters rsaPublicKey = (RSAKeyParameters) publicKey;

			final SubjectPublicKeyInfo info = new SubjectPublicKeyInfo(
					new AlgorithmIdentifier(PKCSObjectIdentifiers.rsaEncryption, DERNull.INSTANCE),
					new RSAPublicKey(rsaPublicKey.getModulus(), rsaPublicKey.getExponent()).toASN1Primitive()
					);
			return info.getEncoded();
		}
	} catch (final IOException x) {
		throw new RuntimeException(x);
	}

	throw new UnsupportedOperationException("publicKey.class=\"" + publicKey.getClass().getName() + "\" not yet supported!");
}
 
开发者ID:subshare,项目名称:subshare,代码行数:31,代码来源:CryptoRegistry.java

示例8: genRSAKeypair

import org.bouncycastle.asn1.pkcs.RSAPublicKey; //导入依赖的package包/类
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);
}
 
开发者ID:xipki,项目名称:xitk,代码行数:12,代码来源:P12KeyGenerator.java

示例9: getRSAPublicKey

import org.bouncycastle.asn1.pkcs.RSAPublicKey; //导入依赖的package包/类
public static PublicKey getRSAPublicKey(byte[] encodedPubKey) throws IOException, NoSuchAlgorithmException, InvalidKeySpecException {
	RSAPublicKey pubKey8 = RSAPublicKey.getInstance(encodedPubKey);
	SubjectPublicKeyInfo info = SubjectPublicKeyInfoFactory.createSubjectPublicKeyInfo(new RSAKeyParameters(false, pubKey8.getModulus(), pubKey8.getPublicExponent()));
	X509EncodedKeySpec spec = new X509EncodedKeySpec(info.getEncoded());
	KeyFactory keyFactory = KeyFactory.getInstance("RSA");
	return keyFactory.generatePublic(spec);
}
 
开发者ID:zsavvas,项目名称:ReCRED_FIDO_UAF_OIDC,代码行数:8,代码来源:KeyCodec.java

示例10: createPublicKey

import org.bouncycastle.asn1.pkcs.RSAPublicKey; //导入依赖的package包/类
public static java.security.interfaces.RSAPublicKey createPublicKey(BigInteger n, BigInteger e) {
    try {
        return (java.security.interfaces.RSAPublicKey) KeyFactory.getInstance("RSA").generatePublic(new RSAPublicKeySpec(n, e));
    } catch (Exception var3) {
        throw new RuntimeException(var3);
    }
}
 
开发者ID:baomidou,项目名称:kisso,代码行数:8,代码来源:RsaKeyHelper.java

示例11: getRSAPublicKey

import org.bouncycastle.asn1.pkcs.RSAPublicKey; //导入依赖的package包/类
public static APublicKey getRSAPublicKey(byte[] b) throws Exception
{
	ASN1InputStream in = new ASN1InputStream(b);
	try
	{
		ASN1Primitive x = in.readObject();
		RSAPublicKey k = RSAPublicKey.getInstance(x);

		return new APublicKey(new RSAKeyParameters(false, k.getModulus(), k.getPublicExponent()));
	}
	finally
	{
		CKit.close(in);
	}
}
 
开发者ID:andy-goryachev,项目名称:PasswordSafe,代码行数:16,代码来源:Crypto.java

示例12: extractPublicRSAKey

import org.bouncycastle.asn1.pkcs.RSAPublicKey; //导入依赖的package包/类
/**
 * makes RSA public key from PEM string.
 *
 * @param s PEM string that contains the key
 * @return
 * @see JCERSAPublicKey
 */
public static RSAPublicKey extractPublicRSAKey(final String s) {
    RSAPublicKey theKey;
    try {
        theKey = new RSAKeyEncoder().parsePEMPublicKey(s);
    } catch (final Exception e) {
        logger.warn("Encryption.extractPublicRSAKey: Caught exception:" + e.getMessage(), e);
        theKey = null;
    }

    return theKey;
}
 
开发者ID:rovemonteux,项目名称:silvertunnel-monteux,代码行数:19,代码来源:Encryption.java

示例13: extractRSAKeyPair

import org.bouncycastle.asn1.pkcs.RSAPublicKey; //导入依赖的package包/类
/**
 * makes RSA private key from PEM string.
 *
 * @param s PEM string that contains the key
 * @return
 * @see JCERSAPublicKey
 */
public static RSAKeyPair extractRSAKeyPair(final String s) {
    RSAKeyPair rsaKeyPair;
    try {
        // parse
        final PEMParser parser = new PEMParser(new StringReader(s));
        final Object o = parser.readObject();
        parser.close();
        // check types
        if (!(o instanceof PEMKeyPair)) {
            throw new IOException("Encryption.extractRSAKeyPair: no private key found in string '" + s + "'");
        }
        final PEMKeyPair keyPair = (PEMKeyPair) o;
        if (keyPair.getPrivateKeyInfo() == null) {
            throw new IOException("Encryption.extractRSAKeyPair: no private key found in key pair of string '" + s + "'");
        }
        if (keyPair.getPublicKeyInfo() == null) {
            throw new IOException("Encryption.extractRSAKeyPair: no public key found in key pair of string '" + s + "'");
        }

        // convert keys and pack them together into a key pair
        final RSAPrivateCrtKey privateKey = new TempJCERSAPrivateCrtKey(keyPair.getPrivateKeyInfo());
        logger.debug("JCEPrivateKey={}", privateKey);
        final RSAPublicKey publicKey = new TempJCERSAPublicKey(keyPair.getPublicKeyInfo());
        rsaKeyPair = new RSAKeyPair(publicKey, privateKey);

    } catch (final Exception e) {
        logger.warn("Encryption.extractPrivateRSAKey: Caught exception:" + e.getMessage());
        rsaKeyPair = null;
    }

    return rsaKeyPair;
}
 
开发者ID:rovemonteux,项目名称:silvertunnel-monteux,代码行数:40,代码来源:Encryption.java

示例14: getRSAPublicKey

import org.bouncycastle.asn1.pkcs.RSAPublicKey; //导入依赖的package包/类
/**
 * Create a key based on the parameters.
 *
 * @param modulus
 * @param publicExponent
 * @return the key
 */
public static RSAPublicKey getRSAPublicKey(final BigInteger modulus, final BigInteger publicExponent) {
    try {
        return (RSAPublicKey) KeyFactory.getInstance("RSA").generatePublic(new RSAPublicKeySpec(modulus, publicExponent));
    } catch (final GeneralSecurityException e) {
        throw new RuntimeException(e);
    }
}
 
开发者ID:rovemonteux,项目名称:silvertunnel-monteux,代码行数:15,代码来源:Encryption.java

示例15: getPKCS1EncodingFromRSAPublicKey

import org.bouncycastle.asn1.pkcs.RSAPublicKey; //导入依赖的package包/类
/**
 * converts a RSAPublicKey into PKCS1-encoding (ASN.1).
 *
 * @param pubKeyStruct
 * @return PKCS1-encoded RSA PUBLIC KEY
 * @see JCERSAPublicKey
 */
public static byte[] getPKCS1EncodingFromRSAPublicKey(final RSAPublicKey pubKeyStruct) {
    try {
        final RSAPublicKeyStructure myKey = new RSAPublicKeyStructure(pubKeyStruct.getModulus(), pubKeyStruct.getPublicExponent());
        final ByteArrayOutputStream bOut = new ByteArrayOutputStream();
        final ASN1OutputStream aOut = new ASN1OutputStream(bOut);
        aOut.writeObject(myKey.toASN1Object());
        aOut.close();
        return bOut.toByteArray();
    } catch (final Exception e) {
        return null;
    }
}
 
开发者ID:rovemonteux,项目名称:silvertunnel-monteux,代码行数:20,代码来源:Encryption.java


注:本文中的org.bouncycastle.asn1.pkcs.RSAPublicKey类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。