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

Java JcaPGPKeyConverter类代码示例

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

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



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

示例1: getX509CertificateFromPgpKeyPair

import org.bouncycastle.openpgp.operator.jcajce.JcaPGPKeyConverter; //导入依赖的package包/类
public static X509Certificate getX509CertificateFromPgpKeyPair( PGPPublicKey pgpPublicKey,
                                                                PGPSecretKey pgpSecretKey, String secretPwd,
                                                                String issuer, String subject, Date dateOfIssue,
                                                                Date dateOfExpiry, BigInteger serial )
        throws PGPException, CertificateException, IOException
{
    JcaPGPKeyConverter c = new JcaPGPKeyConverter();
    PublicKey publicKey = c.getPublicKey( pgpPublicKey );
    PrivateKey privateKey = c.getPrivateKey( pgpSecretKey.extractPrivateKey(
            new JcePBESecretKeyDecryptorBuilder().setProvider( provider ).build( secretPwd.toCharArray() ) ) );

    X509v3CertificateBuilder certBuilder =
            new X509v3CertificateBuilder( new X500Name( issuer ), serial, dateOfIssue, dateOfExpiry,
                    new X500Name( subject ), SubjectPublicKeyInfo.getInstance( publicKey.getEncoded() ) );
    byte[] certBytes = certBuilder.build( new JCESigner( privateKey, "SHA256withRSA" ) ).getEncoded();
    CertificateFactory certificateFactory = CertificateFactory.getInstance( "X.509" );

    return ( X509Certificate ) certificateFactory.generateCertificate( new ByteArrayInputStream( certBytes ) );
}
 
开发者ID:subutai-io,项目名称:base,代码行数:20,代码来源:PGPEncryptionUtil.java


示例2: testGetX509CertificateFromPgpKeyPair

import org.bouncycastle.openpgp.operator.jcajce.JcaPGPKeyConverter; //导入依赖的package包/类
@Test
public void testGetX509CertificateFromPgpKeyPair() throws Exception
{

    Date today = new Date();
    PGPPublicKey pgpPublicKey = PGPEncryptionUtil.findPublicKeyById( findFile( PUBLIC_KEYRING ), PUBLIC_KEY_ID );
    PGPSecretKey pgpSecretKey = PGPEncryptionUtil.findSecretKeyById( findFile( SECRET_KEYRING ), SECRET_KEY_ID );
    X509Certificate x509Certificate = PGPEncryptionUtil
            .getX509CertificateFromPgpKeyPair( pgpPublicKey, pgpSecretKey, SECRET_PWD,
                    "C=ZA, ST=Western Cape, L=Cape Town, O=Thawte Consulting cc,"
                            + " OU=Certification Services Division,"
                            + " CN=Thawte Server CA/[email protected]",
                    "C=US, ST=Maryland, L=Pasadena, O=Brent Baccala,"
                            + "OU=FreeSoft, CN=www.freesoft.org/[email protected]",

                    today, new Date( today.getTime() + ( 1000 * 60 * 60 * 24 ) ), new BigInteger( "1" ) );

    assertNotNull( x509Certificate );


    JcaPGPKeyConverter c = new JcaPGPKeyConverter();
    PublicKey publicKey = c.getPublicKey( pgpSecretKey.getPublicKey() );
    x509Certificate.verify( publicKey, new BouncyCastleProvider() );
}
 
开发者ID:subutai-io,项目名称:base,代码行数:25,代码来源:PGPEncryptionUtilTest.java


示例3: getKey

import org.bouncycastle.openpgp.operator.jcajce.JcaPGPKeyConverter; //导入依赖的package包/类
/**
 * Return the contained private key.
 * 
 * @return PrivateKey
 * @deprecated use a JcaPGPKeyConverter
 */
public PrivateKey getKey()
{
    if (privateKey != null)
    {
        return privateKey;
    }

    try
    {
        return new JcaPGPKeyConverter().setProvider(PGPUtil.getDefaultProvider()).getPrivateKey(this);
    }
    catch (PGPException e)
    {
        throw new IllegalStateException("unable to convert key: " + e.toString());
    }
}
 
开发者ID:NoYouShutup,项目名称:CryptMeme,代码行数:23,代码来源:PGPPrivateKey.java


示例4: encrypt

import org.bouncycastle.openpgp.operator.jcajce.JcaPGPKeyConverter; //导入依赖的package包/类
public static final byte[] encrypt(File pubring, long keyid, byte[] in){
	if(!pubring.exists() || !pubring.isFile()) return null;
	
	try {
		byte[] ret = null;
		
		FileInputStream fis = new FileInputStream(pubring);
		InputStream is = PGPUtil.getDecoderStream(fis);
        PGPPublicKeyRingCollection ring = new PGPPublicKeyRingCollection(is);
        PGPPublicKey pubkey = ring.getPublicKey(keyid);
		if(pubkey.isMasterKey()) {
			System.err.println("Tried to use a non-encryption key. This should never happen.");
			return null;
		}

        PublicKey key = new JcaPGPKeyConverter().getPublicKey(pubkey);
	    Cipher cipher = Cipher.getInstance(key.getAlgorithm() + "/ECB/PKCS1Padding");
	    cipher.init(Cipher.ENCRYPT_MODE, key);
	    ret = cipher.doFinal(in);
        
        is.close();
        fis.close();
		
		return ret;
	} catch (Exception e) {
		System.err.println(e.getLocalizedMessage());
		return null;
	}
}
 
开发者ID:fhissen,项目名称:CrococryptFile,代码行数:30,代码来源:PGPUtils.java


示例5: decrypt

import org.bouncycastle.openpgp.operator.jcajce.JcaPGPKeyConverter; //导入依赖的package包/类
public static final byte[] decrypt(File privring, long keyid, char[] pw, byte[] in){
	if(!privring.exists() || !privring.isFile()) return null;
	
	try {
		byte[] ret = null;
		
		FileInputStream fis = new FileInputStream(privring);
		InputStream is = PGPUtil.getDecoderStream(fis);
		PGPSecretKeyRingCollection ring = new PGPSecretKeyRingCollection(is);
        PGPSecretKey seckey = ring.getSecretKey(keyid);
		if(seckey.isMasterKey()) {
			System.err.println("Someone tried to use a non-encryption key. This should never happen.");
			return null;
		}
		
        PrivateKey key = new JcaPGPKeyConverter().getPrivateKey(
        					seckey.extractPrivateKey(
        						new JcePBESecretKeyDecryptorBuilder().setProvider("BC").build(pw)
        					)
           				);
        
	    Cipher cipher = Cipher.getInstance(key.getAlgorithm() + "/ECB/PKCS1Padding");
	    cipher.init(Cipher.DECRYPT_MODE, key);
	    ret = cipher.doFinal(in);
        
        is.close();
        fis.close();
		
		return ret;
	} catch (Exception e) {
		System.err.println(e.getLocalizedMessage());
		return null;
	}
}
 
开发者ID:fhissen,项目名称:CrococryptFile,代码行数:35,代码来源:PGPUtils.java


示例6: PGPPublicKey

import org.bouncycastle.openpgp.operator.jcajce.JcaPGPKeyConverter; //导入依赖的package包/类
/**
     * @deprecated use JcaPGPKeyConverter.getPGPPublicKey()
 */
public PGPPublicKey(
    int            algorithm,
    PublicKey      pubKey,
    Date           time)
    throws PGPException
{
    this(new JcaPGPKeyConverter().getPGPPublicKey(algorithm, pubKey, time));
}
 
开发者ID:NoYouShutup,项目名称:CryptMeme,代码行数:12,代码来源:PGPPublicKey.java


示例7: ensureKeyConverter

import org.bouncycastle.openpgp.operator.jcajce.JcaPGPKeyConverter; //导入依赖的package包/类
private static void ensureKeyConverter() {
    if (sKeyConverter == null)
        sKeyConverter = new JcaPGPKeyConverter().setProvider(PGPUtils.PROVIDER);
}
 
开发者ID:kontalk,项目名称:desktopclient-java,代码行数:5,代码来源:PGPUtils.java


示例8: ensureKeyConverter

import org.bouncycastle.openpgp.operator.jcajce.JcaPGPKeyConverter; //导入依赖的package包/类
private static void ensureKeyConverter() {
    if (sKeyConverter == null)
        sKeyConverter = new JcaPGPKeyConverter().setProvider(org.kontalk.xmppserver.Security.PROVIDER);
}
 
开发者ID:kontalk,项目名称:tigase-extension,代码行数:5,代码来源:PGPUtils.java


示例9: getKey

import org.bouncycastle.openpgp.operator.jcajce.JcaPGPKeyConverter; //导入依赖的package包/类
/**
 * Return the public key contained in the object.
 * 
 * @param provider provider to construct the key for.
 * @return a JCE/JCA public key.
 * @throws PGPException if the key algorithm is not recognised.
 * @throws NoSuchProviderException if the provider cannot be found.
 * @deprecated use a JcaPGPKeyConverter
 */
public PublicKey getKey(
    String provider)
    throws PGPException, NoSuchProviderException
{
    return new JcaPGPKeyConverter().setProvider(provider).getPublicKey(this);
}
 
开发者ID:NoYouShutup,项目名称:CryptMeme,代码行数:16,代码来源:PGPPublicKey.java



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

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

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

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

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

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