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


Java PasswordFinder类代码示例

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


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

示例1: PEMKeyManager

import org.bouncycastle.openssl.PasswordFinder; //导入依赖的package包/类
public PEMKeyManager() {
    try {
        final Properties p = Play.configuration;

        PEMReader keyReader = new PEMReader(new FileReader(Play.getFile(p.getProperty("certificate.key.file",
                                                                                       "conf/host.key"))),
                                            new PasswordFinder() {
            public char[] getPassword() {
                return p.getProperty("certificate.password", "secret").toCharArray();
            }
        });
        key = ((KeyPair) keyReader.readObject()).getPrivate();

        PEMReader reader = new PEMReader(new FileReader(Play.getFile(p.getProperty("certificate.file", "conf/host.cert"))));
        cert = (X509Certificate) reader.readObject();
    } catch (Exception e) {
        e.printStackTrace();
        Logger.error(e, "");
    }
}
 
开发者ID:eBay,项目名称:restcommander,代码行数:21,代码来源:SslHttpServerContextFactory.java

示例2: encryptedTest

import org.bouncycastle.openssl.PasswordFinder; //导入依赖的package包/类
private void encryptedTest(PrivateKey key, ASN1ObjectIdentifier algorithm)
    throws NoSuchProviderException, NoSuchAlgorithmException, IOException
{
    ByteArrayOutputStream bOut = new ByteArrayOutputStream();
    PEMWriter pWrt = new PEMWriter(new OutputStreamWriter(bOut), "BC");
    PKCS8Generator pkcs8 = new PKCS8Generator(key, algorithm, "BC");

    pkcs8.setPassword("hello".toCharArray());
    
    pWrt.writeObject(pkcs8);

    pWrt.close();

    PEMReader pRd = new PEMReader(new InputStreamReader(new ByteArrayInputStream(bOut.toByteArray())), new PasswordFinder()
    {
        public char[] getPassword()
        {
            return "hello".toCharArray();
        }
    });

    PrivateKey rdKey = (PrivateKey)pRd.readObject();

    assertEquals(key, rdKey);
}
 
开发者ID:credentials,项目名称:irma_future_id,代码行数:26,代码来源:AllTests.java

示例3: doNoPasswordTest

import org.bouncycastle.openssl.PasswordFinder; //导入依赖的package包/类
private void doNoPasswordTest()
    throws IOException
{
    PasswordFinder pGet = new Password("".toCharArray());

    PEMReader pemRd = openPEMResource("smimenopw.pem", pGet);
    Object o;
    PrivateKey key = null;

    while ((o = pemRd.readObject()) != null)
    {
         key = (PrivateKey)o;
    }

    if (key == null)
    {
        fail("private key not detected");
    }
}
 
开发者ID:credentials,项目名称:irma_future_id,代码行数:20,代码来源:ReaderTest.java

示例4: openPEMResource

import org.bouncycastle.openssl.PasswordFinder; //导入依赖的package包/类
private PEMReader openPEMResource(
        String          fileName,
        PasswordFinder  pGet) throws FileNotFoundException
{
 InputStream res = new BufferedInputStream(new FileInputStream(fileName));
    Reader fRd = new BufferedReader(new InputStreamReader(res));
    return new PEMReader(fRd, pGet);
}
 
开发者ID:oneops,项目名称:oneops,代码行数:9,代码来源:CmsCryptoOpenSSLImpl.java

示例5: parsePrivateKey

import org.bouncycastle.openssl.PasswordFinder; //导入依赖的package包/类
public PrivateKey parsePrivateKey(final String key, final String password) throws IOException {

        PasswordFinder pGet = null;

        if (password != null) {
            pGet = new KeyPassword(password.toCharArray());
        }

        final PEMReader privateKey = new PEMReader(new StringReader(key), pGet);
        Object obj = null;
        try {
            obj = privateKey.readObject();
        } finally {
            IOUtils.closeQuietly(privateKey);
        }

        try {

            if (obj instanceof KeyPair) {
                return ((KeyPair) obj).getPrivate();
            }

            return (PrivateKey) obj;
        } catch (final Exception e) {
            throw new IOException("Invalid Key format or invalid password.", e);
        }
    }
 
开发者ID:MissionCriticalCloud,项目名称:cosmic,代码行数:28,代码来源:CertServiceImpl.java

示例6: ResourceHelperKeyPairProvider

import org.bouncycastle.openssl.PasswordFinder; //导入依赖的package包/类
public ResourceHelperKeyPairProvider(String[] resources,
                                     PasswordFinder passwordFinder,
                                     ClassResolver classResolver) {
    this.classResolver = classResolver;
    this.resources = resources;
    this.passwordFinder = passwordFinder;
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:8,代码来源:ResourceHelperKeyPairProvider.java

示例7: getFingerprint

import org.bouncycastle.openssl.PasswordFinder; //导入依赖的package包/类
/**
 * Obtains the fingerprint of the key in the "ab:cd:ef:...:12" format.
 */
public String getFingerprint() throws IOException {
    Security.addProvider(new org.bouncycastle.jce.provider.BouncyCastleProvider());
    Reader r = new BufferedReader(new StringReader(privateKey.toString()));
    PEMReader pem = new PEMReader(r,new PasswordFinder() {
        public char[] getPassword() {
            throw PRIVATE_KEY_WITH_PASSWORD;
        }
    });

    try {
        KeyPair pair = (KeyPair) pem.readObject();
        if(pair==null)  return null;
        PrivateKey key = pair.getPrivate();
        return digest(key);
    } catch (RuntimeException e) {
        if (e==PRIVATE_KEY_WITH_PASSWORD)
            throw new IOException("This private key is password protected, which isn't supported yet");
        throw e;
    }
}
 
开发者ID:hudson3-plugins,项目名称:ec2-plugin,代码行数:24,代码来源:EC2PrivateKey.java

示例8: getPublicFingerprint

import org.bouncycastle.openssl.PasswordFinder; //导入依赖的package包/类
public String getPublicFingerprint() throws IOException {
    Security.addProvider(new org.bouncycastle.jce.provider.BouncyCastleProvider());
    Reader r = new BufferedReader(new StringReader(privateKey.toString()));
    PEMReader pem = new PEMReader(r,new PasswordFinder() {
        public char[] getPassword() {
            throw PRIVATE_KEY_WITH_PASSWORD;
        }
    });

    try {
        KeyPair pair = (KeyPair) pem.readObject();
        if(pair==null)  return null;
        PublicKey key = pair.getPublic();
        return digestOpt(key,"MD5");
    } catch (RuntimeException e) {
        if (e==PRIVATE_KEY_WITH_PASSWORD)
            throw new IOException("This private key is password protected, which isn't supported yet");
        throw e;
    }
}
 
开发者ID:hudson3-plugins,项目名称:ec2-plugin,代码行数:21,代码来源:EC2PrivateKey.java

示例9: encryptedTestNew

import org.bouncycastle.openssl.PasswordFinder; //导入依赖的package包/类
private void encryptedTestNew(PrivateKey key, ASN1ObjectIdentifier algorithm)
    throws NoSuchProviderException, NoSuchAlgorithmException, IOException, OperatorCreationException
{
    ByteArrayOutputStream bOut = new ByteArrayOutputStream();
    PEMWriter pWrt = new PEMWriter(new OutputStreamWriter(bOut), "BC");

    JceOpenSSLPKCS8EncryptorBuilder encryptorBuilder = new JceOpenSSLPKCS8EncryptorBuilder(algorithm);

    encryptorBuilder.setProvider("BC");
    encryptorBuilder.setPasssword("hello".toCharArray());

    PKCS8Generator pkcs8 = new JcaPKCS8Generator(key, encryptorBuilder.build());

    pWrt.writeObject(pkcs8);

    pWrt.close();

    PEMReader pRd = new PEMReader(new InputStreamReader(new ByteArrayInputStream(bOut.toByteArray())), new PasswordFinder()
    {
        public char[] getPassword()
        {
            return "hello".toCharArray();
        }
    });

    PrivateKey rdKey = (PrivateKey)pRd.readObject();

    assertEquals(key, rdKey);
}
 
开发者ID:credentials,项目名称:irma_future_id,代码行数:30,代码来源:AllTests.java

示例10: testPKCS8Plain

import org.bouncycastle.openssl.PasswordFinder; //导入依赖的package包/类
public void testPKCS8Plain()
    throws Exception
{
    KeyPairGenerator kpGen = KeyPairGenerator.getInstance("RSA", "BC");

    kpGen.initialize(1024);

    PrivateKey key = kpGen.generateKeyPair().getPrivate();
    ByteArrayOutputStream bOut = new ByteArrayOutputStream();
    PEMWriter pWrt = new PEMWriter(new OutputStreamWriter(bOut));
    PKCS8Generator pkcs8 = new PKCS8Generator(key);

    pWrt.writeObject(pkcs8);

    pWrt.close();

    PEMReader pRd = new PEMReader(new InputStreamReader(new ByteArrayInputStream(bOut.toByteArray())), new PasswordFinder()
    {
        public char[] getPassword()
        {
            return "hello".toCharArray();
        }
    });

    PrivateKey rdKey = (PrivateKey)pRd.readObject();

    assertEquals(key, rdKey);
}
 
开发者ID:credentials,项目名称:irma_future_id,代码行数:29,代码来源:AllTests.java

示例11: testPKCS8PlainNew

import org.bouncycastle.openssl.PasswordFinder; //导入依赖的package包/类
public void testPKCS8PlainNew()
    throws Exception
{
    KeyPairGenerator kpGen = KeyPairGenerator.getInstance("RSA", "BC");

    kpGen.initialize(1024);

    PrivateKey key = kpGen.generateKeyPair().getPrivate();
    ByteArrayOutputStream bOut = new ByteArrayOutputStream();
    PEMWriter pWrt = new PEMWriter(new OutputStreamWriter(bOut));
    PKCS8Generator pkcs8 = new JcaPKCS8Generator(key, null);

    pWrt.writeObject(pkcs8);

    pWrt.close();

    PEMReader pRd = new PEMReader(new InputStreamReader(new ByteArrayInputStream(bOut.toByteArray())), new PasswordFinder()
    {
        public char[] getPassword()
        {
            return "hello".toCharArray();
        }
    });

    PrivateKey rdKey = (PrivateKey)pRd.readObject();

    assertEquals(key, rdKey);
}
 
开发者ID:credentials,项目名称:irma_future_id,代码行数:29,代码来源:AllTests.java

示例12: openPEMResource

import org.bouncycastle.openssl.PasswordFinder; //导入依赖的package包/类
private PEMReader openPEMResource(
    String          fileName,
    PasswordFinder  pGet)
{
    InputStream res = this.getClass().getResourceAsStream(fileName);
    Reader fRd = new BufferedReader(new InputStreamReader(res));
    return new PEMReader(fRd, pGet);
}
 
开发者ID:credentials,项目名称:irma_future_id,代码行数:9,代码来源:ReaderTest.java

示例13: doDudPasswordTest

import org.bouncycastle.openssl.PasswordFinder; //导入依赖的package包/类
private void doDudPasswordTest(String password, int index, String message)
{
    // illegal state exception check - in this case the wrong password will
    // cause an underlying class cast exception.
    try
    {
        PasswordFinder pGet = new Password(password.toCharArray());

        PEMReader pemRd = openPEMResource("test.pem", pGet);
        Object o;

        while ((o = pemRd.readObject()) != null)
        {
        }

        fail("issue not detected: " + index);
    }
    catch (IOException e)
    {
        if (e.getCause() != null && !e.getCause().getMessage().equals(message))
        {
           e.printStackTrace();
           fail("issue " + index + " exception thrown, but wrong message");
        }
        else if (e.getCause() == null && !e.getMessage().equals(message))
        {
                           e.printStackTrace();
           fail("issue " + index + " exception thrown, but wrong message");
        }
    }
}
 
开发者ID:credentials,项目名称:irma_future_id,代码行数:32,代码来源:ReaderTest.java

示例14: read

import org.bouncycastle.openssl.PasswordFinder; //导入依赖的package包/类
public static PrivateKey read(BufferedInputStream bin, PasswordFinder finder)
throws IOException
{
    PrivateKey privateKey;
    try
    {
        byte b[] = new byte[1000];
        bin.mark(10000);
        PEMReader pemReader = new PEMReader(new InputStreamReader(bin), finder, "BC");
        Object o = pemReader.readObject();
        KeyPair pair = (KeyPair)o;
        privateKey = pair.getPrivate();
        bin.reset();
        String line;
        int num;
        do
        {
            num = bin.read(b);
            line = new String(b);
            bin.reset();
            skipLine(bin);
            bin.mark(1000);
        } while(num > 0 && !line.startsWith("-----END"));
        bin.mark(10000);
        return privateKey;
    }
    catch (IOException e)
    {
        //LOGGER.error((new StringBuilder()).append("Error while reading private key from a file. Exception: ").append(e.getClass().getName()).append(" message:").append(e.getMessage()).toString());
        throw e;
    }
}
 
开发者ID:NLeSC,项目名称:vbrowser,代码行数:33,代码来源:PrivateKeyReader.java

示例15: getPasswordFinder

import org.bouncycastle.openssl.PasswordFinder; //导入依赖的package包/类
public PasswordFinder getPasswordFinder() {
    return passwordFinder;
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:4,代码来源:ResourceHelperKeyPairProvider.java


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