K
kbutterly
Good morning, all:
I have searched but I can't find an answer to what seems to be a pretty
common occurence.
Here's a quick overview. I have a private key (let's say
"13CEF550A7DDFB343BCE6749A349BEF6"), which i have stored on our LINUX
server to encrypt a userID in a Perl script. I now need to decrypt
that UserID using JAVA. I am using AES encryption.
I found the following code:
//create a key to be used
keyGen =
createObject("java","javax.crypto.KeyGenerator").getInstance("AES");
keyGen.init(128);
myKey = keyGen.generateKey();
//instantiate our crypto object
cipher =
createObject("java","javax.crypto.Cipher").getInstance("AES");
// encrypt the string
cipher.init(cipher.ENCRYPT_MODE, myKey);
This would be great, except I don't need to create the private key,
since I already have one.
When I change cipher.init(cipher.ENCRYPT_MODE, myKey); to
cipher.init(cipher.ENCRYPT_MODE, "13CEF550A7DDFB343BCE6749A349BEF6"); I
get an error that the method init was not found. It seems like init
doesn't like a raw string passed to it. The variable myKey is of type
SecretKeySpec, so that's what init must be expecting.
My ultimate goal was to store the private key in a secured file and
read it into a variable, and then pass this variable to the init
method, but that doesn't look like it will work.
My question is, do I have to create a keystore and put my private key
into it? or is there a way to Cast a string to an appropriate object?
I hope this makes sense; apologies if it doesn't. Any references,
resources, links, war stories would be greatly appreciated!
Thanks,
Kathryn
I have searched but I can't find an answer to what seems to be a pretty
common occurence.
Here's a quick overview. I have a private key (let's say
"13CEF550A7DDFB343BCE6749A349BEF6"), which i have stored on our LINUX
server to encrypt a userID in a Perl script. I now need to decrypt
that UserID using JAVA. I am using AES encryption.
I found the following code:
//create a key to be used
keyGen =
createObject("java","javax.crypto.KeyGenerator").getInstance("AES");
keyGen.init(128);
myKey = keyGen.generateKey();
//instantiate our crypto object
cipher =
createObject("java","javax.crypto.Cipher").getInstance("AES");
// encrypt the string
cipher.init(cipher.ENCRYPT_MODE, myKey);
This would be great, except I don't need to create the private key,
since I already have one.
When I change cipher.init(cipher.ENCRYPT_MODE, myKey); to
cipher.init(cipher.ENCRYPT_MODE, "13CEF550A7DDFB343BCE6749A349BEF6"); I
get an error that the method init was not found. It seems like init
doesn't like a raw string passed to it. The variable myKey is of type
SecretKeySpec, so that's what init must be expecting.
My ultimate goal was to store the private key in a secured file and
read it into a variable, and then pass this variable to the init
method, but that doesn't look like it will work.
My question is, do I have to create a keystore and put my private key
into it? or is there a way to Cast a string to an appropriate object?
I hope this makes sense; apologies if it doesn't. Any references,
resources, links, war stories would be greatly appreciated!
Thanks,
Kathryn