本文整理汇总了Java中net.oauth.signature.pem.PKCS1EncodedKeySpec类的典型用法代码示例。如果您正苦于以下问题:Java PKCS1EncodedKeySpec类的具体用法?Java PKCS1EncodedKeySpec怎么用?Java PKCS1EncodedKeySpec使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
PKCS1EncodedKeySpec类属于net.oauth.signature.pem包,在下文中一共展示了PKCS1EncodedKeySpec类的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。
示例1: getPrivateKeyFromPem
import net.oauth.signature.pem.PKCS1EncodedKeySpec; //导入依赖的package包/类
private PrivateKey getPrivateKeyFromPem(String pem)
throws GeneralSecurityException, IOException {
InputStream stream = new ByteArrayInputStream(
pem.getBytes("UTF-8"));
PEMReader reader = new PEMReader(stream);
byte[] bytes = reader.getDerBytes();
KeySpec keySpec;
if (PEMReader.PRIVATE_PKCS1_MARKER.equals(reader.getBeginMarker())) {
keySpec = (new PKCS1EncodedKeySpec(bytes)).getKeySpec();
}
else if (PEMReader.PRIVATE_PKCS8_MARKER.equals(reader.getBeginMarker())) {
keySpec = new PKCS8EncodedKeySpec(bytes);
}
else {
throw new IOException("Invalid PEM file: Unknown marker " +
"for private key " + reader.getBeginMarker());
}
KeyFactory fac = KeyFactory.getInstance("RSA");
return fac.generatePrivate(keySpec);
}
开发者ID:infinitiessoft,项目名称:keystone4j,代码行数:25,代码来源:PEMx509KeyManager.java
示例2: getPrivateKeyFromPem
import net.oauth.signature.pem.PKCS1EncodedKeySpec; //导入依赖的package包/类
private PrivateKey getPrivateKeyFromPem(String pem)
throws GeneralSecurityException, IOException {
InputStream stream = new ByteArrayInputStream(
pem.getBytes("UTF-8"));
PEMReader reader = new PEMReader(stream);
byte[] bytes = reader.getDerBytes();
KeySpec keySpec;
if (PEMReader.PRIVATE_PKCS1_MARKER.equals(reader.getBeginMarker())) {
keySpec = (new PKCS1EncodedKeySpec(bytes)).getKeySpec();
} else if (PEMReader.PRIVATE_PKCS8_MARKER.equals(reader.getBeginMarker())) {
keySpec = new PKCS8EncodedKeySpec(bytes);
} else {
throw new IOException("Invalid PEM file: Unknown marker " +
"for private key " + reader.getBeginMarker());
}
KeyFactory fac = KeyFactory.getInstance("RSA");
return fac.generatePrivate(keySpec);
}
开发者ID:sakaiproject,项目名称:sakai,代码行数:23,代码来源:RSA_SHA1.java
示例3: configureClientCert
import net.oauth.signature.pem.PKCS1EncodedKeySpec; //导入依赖的package包/类
private static KeyManager[] configureClientCert(String clientCertFile, String clientKeyFile, char[] clientKeyPassword, String clientKeyAlgo) throws Exception {
try {
InputStream certInputStream = openFile(clientCertFile);
CertificateFactory certFactory = CertificateFactory.getInstance("X509");
X509Certificate cert = (X509Certificate)certFactory.generateCertificate(certInputStream);
InputStream keyInputStream = openFile(clientKeyFile);
PEMReader reader = new PEMReader(keyInputStream);
RSAPrivateCrtKeySpec keySpec = new PKCS1EncodedKeySpec(reader.getDerBytes()).getKeySpec();
KeyFactory kf = KeyFactory.getInstance(clientKeyAlgo);
RSAPrivateKey privKey = (RSAPrivateKey)kf.generatePrivate(keySpec);
KeyStore keyStore = KeyStore.getInstance("JKS");
keyStore.load(null);
String alias = cert.getSubjectX500Principal().getName();
keyStore.setKeyEntry(alias, privKey, clientKeyPassword, new Certificate[]{cert});
KeyManagerFactory keyManagerFactory = KeyManagerFactory.getInstance(KeyManagerFactory.getDefaultAlgorithm());
keyManagerFactory.init(keyStore, clientKeyPassword);
return keyManagerFactory.getKeyManagers();
} catch (Exception e) {
log.log(Level.SEVERE, "Could not create key manager for " + clientCertFile + " (" + clientKeyFile + ")", e);
throw e;
}
}
开发者ID:jgroups-extras,项目名称:jgroups-kubernetes,代码行数:28,代码来源:CertificateStreamProvider.java
示例4: configureClientCert
import net.oauth.signature.pem.PKCS1EncodedKeySpec; //导入依赖的package包/类
private KeyManager[] configureClientCert(String clientCertFile, String clientKeyFile, char[] clientKeyPassword, String clientKeyAlgo) throws Exception {
try {
InputStream certInputStream = openFile(clientCertFile);
CertificateFactory certFactory = CertificateFactory.getInstance("X509");
X509Certificate cert = (X509Certificate)certFactory.generateCertificate(certInputStream);
InputStream keyInputStream = openFile(clientKeyFile);
PEMReader reader = new PEMReader(keyInputStream);
RSAPrivateCrtKeySpec keySpec = new PKCS1EncodedKeySpec(reader.getDerBytes()).getKeySpec();
KeyFactory kf = KeyFactory.getInstance(clientKeyAlgo);
RSAPrivateKey privKey = (RSAPrivateKey)kf.generatePrivate(keySpec);
KeyStore keyStore = KeyStore.getInstance("JKS");
keyStore.load(null);
String alias = cert.getSubjectX500Principal().getName();
keyStore.setKeyEntry(alias, privKey, clientKeyPassword, new Certificate[]{cert});
KeyManagerFactory keyManagerFactory = KeyManagerFactory.getInstance(KeyManagerFactory.getDefaultAlgorithm());
keyManagerFactory.init(keyStore, clientKeyPassword);
return keyManagerFactory.getKeyManagers();
} catch (Exception e) {
log.log(Level.SEVERE, "Could not create key manager for " + clientCertFile + " (" + clientKeyFile + ")", e);
throw e;
}
}
开发者ID:jboss-openshift,项目名称:openshift-ping,代码行数:28,代码来源:CertificateStreamProvider.java
注:本文中的net.oauth.signature.pem.PKCS1EncodedKeySpec类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论