0% found this document useful (0 votes)
113 views3 pages

En Crypt Manager Lee Pkcs8con Password

This Java class contains methods for encrypting and signing data using public/private key cryptography. It includes methods for reading private and public keys from files, signing data with the private key, verifying signatures with the public key, and writing the private key back to a file. Additional methods are provided for loading private keys from byte arrays.
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
113 views3 pages

En Crypt Manager Lee Pkcs8con Password

This Java class contains methods for encrypting and signing data using public/private key cryptography. It includes methods for reading private and public keys from files, signing data with the private key, verifying signatures with the public key, and writing the private key back to a file. Additional methods are provided for loading private keys from byte arrays.
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd

package [Link]; import [Link].*; import [Link].*; import [Link].*; import [Link].

*; public class EncryptManager { private PrivateKey privateKey = null; private PublicKey publicKey= null; public void readPrivateKey(String URI) throws Exception { FileInputStream keyfis = new FileInputStream(URI); byte[] encKey = new byte[[Link]()]; [Link](encKey); [Link](); PKCS8EncodedKeySpec privKeySpec = new PKCS8EncodedKeySpec(encKey ); KeyFactory keyFactory = [Link]("RSA"); privateKey = [Link](privKeySpec); } public void readPublicKey(String URI) throws Exception { FileInputStream keyfis = new FileInputStream(URI); byte[] encKey = new byte[[Link]()]; [Link](encKey); [Link](); X509EncodedKeySpec pubKeySpec = new X509EncodedKeySpec(encKey); KeyFactory keyFactory = [Link]("RSA"); publicKey = [Link](pubKeySpec); } public void readKeys(String publicURI, String privateURI)throws Exceptio n { readPublicKey(publicURI); readPrivateKey(privateURI); } public String sign(String buffer) throws Exception { Signature rsa = [Link]("SHA1withRSA"); [Link](privateKey); [Link]([Link]()); String signature = new String([Link]()); return signature; } public boolean verify(String signature, String buffer) throws Exception { Signature rsa = [Link]("SHA1withRSA"); [Link](publicKey); [Link]([Link]()); return [Link]([Link]()); } public void writePrivateKey(String URI) throws Exception { byte[] enckey = [Link](); FileOutputStream keyfos = new FileOutputStream(URI); [Link](enckey);

[Link](); } public String readPrivateKey2(byte[] bytes) throws Exception { //return [Link](); //FileInputStream keyfis = new FileInputStream(URI); //byte[] encKey = new byte[[Link]()]; //[Link](encKey); //byte[] encKey= new byte[2048]; //[Link](encKey,0,2048); //[Link](); //return [Link](); //PKCS8EncodedKeySpec privKeySpec = new PKCS8EncodedKeySpec(encK ey); //KeyFactory keyFactory = [Link]("RSA"); //privateKey = [Link](privKeySpec); PKCS8EncodedKeySpec privKeySpec = new PKCS8EncodedKeySpec(bytes) ; KeyFactory keyFactory = [Link]("RSA"); privateKey = [Link](privKeySpec); return "nanchis"; //return [Link](); } public String readPKCS8PrivateKey(byte[] bytes, String passwd)throws E xception { /* byte[] decrypted = (passwd != null) ? getBytes(in, [Link]()) : getBytes(in); */ PKCS8Key key= new PKCS8Key(bytes, [Link]()); PKCS8EncodedKeySpec keysp = new PKCS8EncodedKeySpec([Link] Bytes()); KeyFactory kf = [Link]("RSA"); privateKey= [Link](keysp); return [Link](); } public PrivateKey getPrivateKey(){ return [Link]; } /* public static PrivateKey loadPKCS8PrivateKey(InputStream in, String pa sswd) throws Exception { byte[] decrypted = (passwd != null) ? getBytes(in, [Link]()) : getBytes(in); PKCS8EncodedKeySpec keysp = new PKCS8EncodedKeySpec(decrypted); KeyFactory kf = [Link]("RSA"); return [Link](keysp); } */ /* private static byte[] getBytes(InputStream in) throws Exception {

try { return [Link](in); } finally { [Link](); } } */ /* private static byte[] getBytes(InputStream in, char[] passwd) throws Exception { try { [Link].PKCS8Key pkcs8 = new [Link].PKCS8Key( in, passwd); return [Link](); } finally { [Link](); } } */ }

You might also like