开发者

How to convert string to key to be used in encryption?

开发者 https://www.devze.com 2023-02-07 12:45 出处:网络
Hi All I want to convert the string (taken as input from user) into a secretkey.I am 开发者_如何学JAVAcoding in J2ME.The algorithm used is blowfish.The Java cryptography APIs are not available in Java

Hi All I want to convert the string (taken as input from user) into a secretkey.I am 开发者_如何学JAVAcoding in J2ME.The algorithm used is blowfish.


The Java cryptography APIs are not available in Java ME.

You'll need to download the Bouncy Castle lightweight cryptography API, which supports Java ME. You can then extract the classes you need from there. I found a code example here that should help you get started.

About charsets: Java ME does indeed support UTF-8, so that's always a safe bet. And a good idea, yes, although you'll see a lot of code that doesn't specify a charset.


Edit: Please see Eric's answer. This is not available in J2ME.

To convert a string to a key, you can do:

String strkey = "My key goes here";
SecretKeySpec key = new SecretKeySpec(strkey.getBytes("UTF-8"), "Blowfish");
0

精彩评论

暂无评论...
验证码 换一张
取 消