How to use a certificate for encryption in java se

时间:2015-06-20 09:37:27

标签: java encryption certificate

I've to code an app in java that let the user write a text and use a certificate to encrypt this string and show it (encrypted) in a textfield. I coded the graphical interface but i've searched for how to use certificate to encrypt/decrypt a variable in java and i didn't find something for my case ! Thanks for your help.

1 个答案:

答案 0 :(得分:1)

您的证书可以导出为文件(例如:“mycert.cer”)。然后使用JCA(Java Cryptography Architecture)提供的API来操作它。

例如,要阅读证书,您可以使用

select()

FileInputStream fis = new FileInputStream("mycert.cer"); CertificateFactory cf = CertificateFactory.getInstance("X509"); X509Certificate crt = (X509Certificate) cf.generateCertificate(fis); 对象的公钥,您可以加密您的文本。您需要的一切都是herehere