本文整理汇总了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, "");
}
}
示例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);
}
示例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");
}
}
示例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);
}
示例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);
}
}
示例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;
}
示例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;
}
}
示例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;
}
}
示例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);
}
示例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);
}
示例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);
}
示例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);
}
示例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");
}
}
}
示例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;
}
}
示例15: getPasswordFinder
import org.bouncycastle.openssl.PasswordFinder; //导入依赖的package包/类
public PasswordFinder getPasswordFinder() {
return passwordFinder;
}