在Java中使用BlowFish进行加密
下面的代码对于我使用BlowFish加密字符串进行加密很好。
// create a key generator based upon the Blowfish cipher
KeyGenerator keygenerator = KeyGenerator.getInstance("Blowfish");
// create a key
SecretKey secretkey = keygenerator.generateKey();
// create a cipher based upon Blowfish
Cipher cipher = Cipher.getInstance("Blowfish");
// initialise cipher to with secret key
cipher.init(Cipher.ENCRYPT_MODE, secretkey);
// get the text to encrypt
String inputText = "MyTextToEncrypt";
// encrypt message
byte[] encrypted = cipher.doFinal(inputText.getBytes());
如果我想定义自己的密钥,我该怎么做?