Public key encryption help
Hi all,
I'll try to explain this as best as I can. I need to design an encryption application which deals with the following:
1. Encryption to be done using a public key at the front end of the application.
2. Decryption to be done using a private key at the back end of the application, but:
3. The private key needs to be secured in some way and not available in a file or similar; probably by requiring the admin user to submit a password in order for the key to be generated.
I have generated a public and private key pair using the following code:
KeyPairGenerator kpg =null;
kpg = KeyPairGenerator.getInstance("RSA","BC");
SecureRandom srandom =new SecureRandom();
kpg.initialize(1024, srandom);
KeyPair kp = kpg.generateKeyPair();
PrivateKey priKey = kp.getPrivate();
PublicKey pubKey = kp.getPublic();
But now that I've done that I have no idea how to achieve the important bits:
1. Encryption with my predefined public key.
2. Decryption with my predefined private key, in conjunction with a user-submitted password.
Help? :)
[1258 byte] By [
jbbnza] at [2007-11-27 10:46:26]

# 4
It may or may not be worth mentioning that any functions are being called and having their returned values parsed by PHP, by the way.
I envision it like this:
/*** PHP ***/
// load Java class
$crypt = new Java('Crypt');
// encrypt a string
$crypt->Encrypt($someString);
// decrypt a string
$crypt->Decrypt($someString, $password);
/*** JAVA ***/
// encryption method declaration
public String Encrypt(String plaintext);
// decryption method declaration
public String Decrypt(String ciphertext, String password);
(Whether the methods would actually return Strings I have no idea.)
jbbnza at 2007-7-28 20:18:55 >

# 6
/me resumes work on this project
I've created a keystore with keytool, but when I try to initialise a KeyStore in my java application I get this:
Code:
KeyStore keyStore = KeyStore.getInstance("JCEKS");
Error:
java.lang.Exception: CreateInstance failed: new Xcryption. Cause: java.security.KeyStoreException: JCEKS
Any ideas? :)
Message was edited by:
jbbnz
jbbnza at 2007-7-28 20:18:55 >

# 8
OK turns out this was a Tomcat problem; I needed to get sunjce_provider.jar into my Tomcat path.
I'm getting a different error now, however.
NoClassDefFoundError: com.sun.crypto.provider.SunJCE_aa. -- Unable to call constructor
This is occurring on the getKey() line of this code:
KeyStore keyStore = KeyStore.getInstance("JCEKS", new com.sun.crypto.provider.SunJCE());
FileInputStream fis = new FileInputStream("/path/to/file.jceks");
keyStore.load(fis, "mypassword".toCharArray());
Key public_key = keyStore.getKey("mykeystorealias", "mypassword".toCharArray());
This seems odd because the SunJCE_aa class appears to be part of that .jar file...
jbbnza at 2007-7-28 20:18:55 >
