• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Java RSAPrivateKey类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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

示例1: getRSAPrivateKey

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

		return new APrivateKey(new RSAPrivateCrtKeyParameters
		(
			k.getModulus(), 
			k.getPublicExponent(),
			k.getPrivateExponent(),
			k.getPrime1(),
			k.getPrime2(),
			k.getExponent1(),
			k.getExponent2(),
			k.getCoefficient()
		));
	}
	finally
	{
		CKit.close(in);
	}
}
 
开发者ID:andy-goryachev,项目名称:PasswordSafe,代码行数:26,代码来源:Crypto.java


示例2: engineTranslateKey

import org.bouncycastle.asn1.pkcs.RSAPrivateKey; //导入依赖的package包/类
protected Key engineTranslateKey(
    Key key)
    throws InvalidKeyException
{
    if (key instanceof RSAPublicKey)
    {
        return new BCRSAPublicKey((RSAPublicKey)key);
    }
    else if (key instanceof RSAPrivateCrtKey)
    {
        return new BCRSAPrivateCrtKey((RSAPrivateCrtKey)key);
    }
    else if (key instanceof java.security.interfaces.RSAPrivateKey)
    {
        return new BCRSAPrivateKey((java.security.interfaces.RSAPrivateKey)key);
    }

    throw new InvalidKeyException("key type unknown");
}
 
开发者ID:Appdome,项目名称:ipack,代码行数:20,代码来源:KeyFactorySpi.java


示例3: generatePrivate

import org.bouncycastle.asn1.pkcs.RSAPrivateKey; //导入依赖的package包/类
public PrivateKey generatePrivate(PrivateKeyInfo keyInfo)
    throws IOException
{
    ASN1ObjectIdentifier algOid = keyInfo.getPrivateKeyAlgorithm().getAlgorithm();

    if (RSAUtil.isRsaOid(algOid))
    {
        RSAPrivateKey rsaPrivKey = RSAPrivateKey.getInstance(keyInfo.parsePrivateKey());

        if (rsaPrivKey.getCoefficient().intValue() == 0)
        {
            return new BCRSAPrivateKey(rsaPrivKey);
        }
        else
        {
            return new BCRSAPrivateCrtKey(keyInfo);
        }
    }
    else
    {
        throw new IOException("algorithm identifier " + algOid + " in key not recognised");
    }
}
 
开发者ID:thedrummeraki,项目名称:Aki-SSL,代码行数:24,代码来源:KeyFactorySpi.java


示例4: TerminalAuthenticationRSA

import org.bouncycastle.asn1.pkcs.RSAPrivateKey; //导入依赖的package包/类
/**
	 * @param caDomainParamter
	 */
	public TerminalAuthenticationRSA(DomainParameter caDomainParamter, AmRSAPublicKey taPublicKey, RSAPrivateKey taSecretKey) {
		super(caDomainParamter);
		//TODO id_TA mit RSA implementieren.
		throw new UnsupportedOperationException("Terminal Authentication with RSA not yet implemented!");
		
//		BigInteger modulus = taPublicKey.getModulus();
//		BigInteger pubExp = taPublicKey.getPublicExponent();
//		
//		if (taPublicKey.getOID().toString().equals(BSIObjectIdentifiers.id_TA_RSA_PSS_SHA_1.toString())) {
//			signingAlgorithm = "SHA1withRSA";
//		} else if (taPublicKey.getOID().toString().equals(BSIObjectIdentifiers.id_TA_RSA_PSS_SHA_256.toString())) {
//			signingAlgorithm = "SHA256withRSA";
//		} else if (taPublicKey.getOID().toString().equals(BSIObjectIdentifiers.id_TA_RSA_PSS_SHA_512.toString())) {
//			signingAlgorithm = "SHA512withRSA";
//		} else if (taPublicKey.getOID().toString().equals(BSIObjectIdentifiers.id_TA_RSA_v1_5_SHA_1.toString())) {
//			signingAlgorithm = "SHA1withRSA";
//		} else if (taPublicKey.getOID().toString().equals(BSIObjectIdentifiers.id_TA_RSA_v1_5_SHA_256.toString())) {
//			signingAlgorithm = "SHA256withRSA";
//		} else if (taPublicKey.getOID().toString().equals(BSIObjectIdentifiers.id_TA_RSA_v1_5_SHA_512.toString())) {
//			signingAlgorithm = "SHA512withRSA";
//		}
//		
//		this.terminalSK = taSecretKey;
	}
 
开发者ID:tsenger,项目名称:animamea,代码行数:28,代码来源:TerminalAuthenticationRSA.java


示例5: encodePrivateKey

import org.bouncycastle.asn1.pkcs.RSAPrivateKey; //导入依赖的package包/类
/**
 * <p>
 * Encode (serialise) a private key in order to store it or transport it over a network.
 * </p><p>
 * <b>Important: You should keep your private key secret!</b> Thus, you might want to encrypt the result before
 * storing it to a file or sending it somewhere!
 * </p>
 * @param privateKey the private key to be encoded; must not be <code>null</code>.
 * @return the encoded (serialised) form of the private key. Can be passed to {@link #decodePrivateKey(byte[])} to
 * reverse this method.
 * @see #decodePrivateKey(byte[])
 * @see #encodePublicKey(CipherParameters)
 */
public byte[] encodePrivateKey(final CipherParameters privateKey)
{
	if (privateKey == null)
		throw new IllegalArgumentException("privateKey == null");

	// TODO use a class-based map or similar registry!
	try {
		if (privateKey instanceof RSAPrivateCrtKeyParameters) {
			final RSAPrivateCrtKeyParameters rsaPrivateKey = (RSAPrivateCrtKeyParameters) privateKey;

			final PrivateKeyInfo info = new PrivateKeyInfo(
					new AlgorithmIdentifier(PKCSObjectIdentifiers.rsaEncryption, DERNull.INSTANCE),
					new RSAPrivateKey(
							rsaPrivateKey.getModulus(), rsaPrivateKey.getPublicExponent(), rsaPrivateKey.getExponent(),
							rsaPrivateKey.getP(), rsaPrivateKey.getQ(), rsaPrivateKey.getDP(),
							rsaPrivateKey.getDQ(), rsaPrivateKey.getQInv()).toASN1Primitive()
					);
			return info.getEncoded();
		}
	} catch (final IOException x) {
		throw new RuntimeException(x);
	}

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


示例6: loadPrivateKeyResource

import org.bouncycastle.asn1.pkcs.RSAPrivateKey; //导入依赖的package包/类
static AsymmetricKeyParameter loadPrivateKeyResource(String resource)
    throws IOException
{

    PemObject pem = loadPemResource(resource);
    if (pem.getType().endsWith("RSA PRIVATE KEY"))
    {
        RSAPrivateKey rsa = RSAPrivateKey.getInstance(pem.getContent());
        return new RSAPrivateCrtKeyParameters(rsa.getModulus(), rsa.getPublicExponent(),
            rsa.getPrivateExponent(), rsa.getPrime1(), rsa.getPrime2(), rsa.getExponent1(),
            rsa.getExponent2(), rsa.getCoefficient());
    }
    if (pem.getType().endsWith("PRIVATE KEY"))
    {
        return PrivateKeyFactory.createKey(pem.getContent());
    }
    throw new IllegalArgumentException("'resource' doesn't specify a valid private key");
}
 
开发者ID:credentials,项目名称:irma_future_id,代码行数:19,代码来源:TlsTestUtils.java


示例7: JCERSAPrivateCrtKey

import org.bouncycastle.asn1.pkcs.RSAPrivateKey; //导入依赖的package包/类
/**
 * construct an RSA key from a private key info object.
 */
JCERSAPrivateCrtKey(
    PrivateKeyInfo  info)
    throws IOException
{
    this(org.bouncycastle.asn1.pkcs.RSAPrivateKey.getInstance(info.parsePrivateKey()));
}
 
开发者ID:Appdome,项目名称:ipack,代码行数:10,代码来源:JCERSAPrivateCrtKey.java


示例8: engineGeneratePrivate

import org.bouncycastle.asn1.pkcs.RSAPrivateKey; //导入依赖的package包/类
protected PrivateKey engineGeneratePrivate(
    KeySpec keySpec)
    throws InvalidKeySpecException
{
    if (keySpec instanceof PKCS8EncodedKeySpec)
    {
        try
        {
            return generatePrivate(PrivateKeyInfo.getInstance(((PKCS8EncodedKeySpec)keySpec).getEncoded()));
        }
        catch (Exception e)
        {
            //
            // in case it's just a RSAPrivateKey object... -- openSSL produces these
            //
            try
            {
                return new BCRSAPrivateCrtKey(
                    RSAPrivateKey.getInstance(((PKCS8EncodedKeySpec)keySpec).getEncoded()));
            }
            catch (Exception ex)
            {
                throw new ExtendedInvalidKeySpecException("unable to process key spec: " + e.toString(), e);
            }
        }
    }
    else if (keySpec instanceof RSAPrivateCrtKeySpec)
    {
        return new BCRSAPrivateCrtKey((RSAPrivateCrtKeySpec)keySpec);
    }
    else if (keySpec instanceof RSAPrivateKeySpec)
    {
        return new BCRSAPrivateKey((RSAPrivateKeySpec)keySpec);
    }

    throw new InvalidKeySpecException("Unknown KeySpec type: " + keySpec.getClass().getName());
}
 
开发者ID:Appdome,项目名称:ipack,代码行数:38,代码来源:KeyFactorySpi.java


示例9: BCRSAPrivateCrtKey

import org.bouncycastle.asn1.pkcs.RSAPrivateKey; //导入依赖的package包/类
/**
 * construct an RSA key from a private key info object.
 */
BCRSAPrivateCrtKey(
    PrivateKeyInfo info)
    throws IOException
{
    this(RSAPrivateKey.getInstance(info.parsePrivateKey()));
}
 
开发者ID:Appdome,项目名称:ipack,代码行数:10,代码来源:BCRSAPrivateCrtKey.java


示例10: toRSAPrivateKey

import org.bouncycastle.asn1.pkcs.RSAPrivateKey; //导入依赖的package包/类
public static RSAPrivateKey toRSAPrivateKey(RSAPrivateCrtKeyParameters k) throws Exception
{
	// hope this is correct
	return new RSAPrivateKey
	(
		k.getModulus(), 
		k.getPublicExponent(),
		k.getExponent(),
		k.getP(),
		k.getQ(),
		k.getDP(),
		k.getDQ(),
		k.getQInv()
	);
}
 
开发者ID:andy-goryachev,项目名称:PasswordSafe,代码行数:16,代码来源:Crypto.java


示例11: TempJCERSAPrivateCrtKey

import org.bouncycastle.asn1.pkcs.RSAPrivateKey; //导入依赖的package包/类
/**
 * construct an RSA key from a private key info object.
 */
TempJCERSAPrivateCrtKey(
    PrivateKeyInfo  info)
    throws IOException
{
    this(org.bouncycastle.asn1.pkcs.RSAPrivateKey.getInstance(info.parsePrivateKey()));
}
 
开发者ID:rovemonteux,项目名称:silvertunnel-monteux,代码行数:10,代码来源:TempJCERSAPrivateCrtKey.java


示例12: loadKeys

import org.bouncycastle.asn1.pkcs.RSAPrivateKey; //导入依赖的package包/类
public void loadKeys() {
    try {
        FileInputStream idCertIS = new FileInputStream(new File("keys/identity.crt"));
        FileInputStream linkCertIS = new FileInputStream(new File("keys/link.crt"));
        FileInputStream authCertIS = new FileInputStream(new File("keys/auth.crt"));

        CertificateFactory cf = null;
        cf = CertificateFactory.getInstance("X.509");

        identityCert = (X509Certificate) cf.generateCertificate(idCertIS);
        log.info("Our Identity Cert Digest: " + Hex.toHexString(TorCrypto.getSHA1().digest(TorCrypto.publicKeyToASN1((RSAPublicKey) identityCert.getPublicKey()))));

        linkCert = (X509Certificate) cf.generateCertificate(linkCertIS);
        log.info("Our Link Cert Digest: " + Hex.toHexString(TorCrypto.getSHA1().digest(TorCrypto.publicKeyToASN1((RSAPublicKey) linkCert.getPublicKey()))));

        authCert = (X509Certificate) cf.generateCertificate(authCertIS);
        log.info("Our Auth Cert Digest: " + Hex.toHexString(TorCrypto.getSHA1().digest(TorCrypto.publicKeyToASN1((RSAPublicKey) authCert.getPublicKey()))));

        identityPubKey = (RSAPublicKey) identityCert.getPublicKey();

        FileReader in = new FileReader("keys/identity.key");
        identityPrivKey = RSAPrivateKey.getInstance(new PemReader(in).readPemObject().getContent());
    } catch (CertificateException | IOException e) {
        log.error("Unable to load server public key");
        System.exit(1);
    }
}
 
开发者ID:owenson,项目名称:tor-research-framework,代码行数:28,代码来源:TorServerSocket.java



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java SystemProperties类代码示例发布时间:2022-05-21
下一篇:
Java IStorageSourceService类代码示例发布时间:2022-05-21
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap