在Java中使用BlowFish进行加密
发布时间:2020-12-14 16:38:18 所属栏目:Java 来源:网络整理
导读:以下代码对我来说加密使用BlowFish加密的字符串正常. // create a key generator based upon the Blowfish cipher KeyGenerator keygenerator = KeyGenerator.getInstance("Blowfish"); // create a key SecretKey secretkey = keygenerator.generateKey();
以下代码对我来说加密使用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()); 如果我想定义我自己的秘密密钥,该怎么做? 解决方法String Key = "Something"; byte[] KeyData = Key.getBytes(); SecretKeySpec KS = new SecretKeySpec(KeyData,"Blowfish"); Cipher cipher = Cipher.getInstance("Blowfish"); cipher.init(Cipher.ENCRYPT_MODE,KS); (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |