public static void mergePfx(String prikey, String cert, String pwd, String path) throws Exception {
byte[] priKey = Base64.decode(prikey);
byte[] CertBytes = Base64.decode(cert);
ByteArrayInputStream in = new ByteArrayInputStream(CertBytes);
CertificateFactory cf;
cf = CertificateFactory.getInstance("X.509");
X509Certificate x509Cert = (X509Certificate) cf.generateCertificate(in);
// 创建KeyStore
KeyStore store = KeyStore.getInstance("PKCS12");
PKCS8EncodedKeySpec priKeySpec = new PKCS8EncodedKeySpec(priKey);
KeyFactory keyFactory = KeyFactory.getInstance("RSA");
PrivateKey key = keyFactory.generatePrivate(priKeySpec);
store.load(null, null);
store.setKeyEntry("", key, pwd.toCharArray(), new Certificate[]{x509Cert});
FileOutputStream fout = new FileOutputStream(path);
store.store(fout, pwd.toCharArray());
fout.close();
}
上面是java的一个函数,怎么在c#中怎么用
ikvm插件将java转为c#
都没java的环境。
只能重新写啊
不会呀。
C# 没有 KeyStore
先弄逐个懂Java函数功能和含义,再取搜对应的C#代码,然后拼接一起就好
比如 “C# base64解码”, “C# RSA加密”, “C#获取证书”
实在不行C# 也能直接用java的代码,安装插件和依赖,楼上说的那个就行。
参考:
谢谢。方向是正确的。