Tag: 河豚

Java – 使用blowfish加密时缺少最终字符

我正在使用一些使用Blowfish加密文本文件内容的j​​ava代码。 当我将加密文件转换回来(即解密它)时,字符串从末尾开始缺少一个字符。 有什么想法吗? 我对Java很陌生,并且在没有运气的情况下花了好几个小时。 war_and_peace.txt文件只包含字符串“This is some text”。 decrypted.txt包含“这是一些tex”(最后没有)。 这是java代码: public static void encrypt(String key, InputStream is, OutputStream os) throws Throwable { encryptOrDecrypt(key, Cipher.ENCRYPT_MODE, is, os); } public static void decrypt(String key, InputStream is, OutputStream os) throws Throwable { encryptOrDecrypt(key, Cipher.DECRYPT_MODE, is, os); } private static byte[] getBytes(String toGet) { try { byte[] retVal = […]

Blowfish在Java / Scala中加密并在bash中解密

我正在尝试构建一个工具来解密scala应用程序中加密的bash中的内容: 但首先,我要在两种语言中成功编码相同的消息并使它们相等: 鉴于密码“0123456789abcdef” (hex:“30313233343536373839616263646566”和字节[]:[48,49,50,51,52,53,54,55,56,57,97,98,99,100,101,102]) scala> import javax.crypto.Cipher scala> import javax.crypto.spec.SecretKeySpec scala> val cipher = Cipher.getInstance(“Blowfish”) scala> cipher.init(Cipher.ENCRYPT_MODE, new SecretKeySpec(“0123456789abcdef”.getBytes(“utf-8”), “Blowfish”)) scala> javax.xml.bind.DatatypeConverter.printBase64Binary(cipher.doFinal(“message”.getBytes(“utf-8”))) res7: String = K679Jz06jmc= 但我无法在bash中使用openssl重现相同的内容。 $ echo “message” | openssl enc -a -e -blowfish -nosalt -nopad -k “0123456789abcdef” LJ3iFJ2/mYk= $ echo “message” | openssl enc -a -e -blowfish -nosalt -nopad -k “30313233343536373839616263646566” JkkJgYv3fQg= […]

使用Blowfish在Java中解密

你好, 我用Blowfish用Java加密和解密。 加密工作正常,但解密失败。 这是我的解密Java代码: String encryptedString = … ; String decryptedString = null; SecretKeySpec key = new SecretKeySpec(myKey.getBytes(), “Blowfish”); Cipher cipher; try { cipher = Cipher.getInstance(“Blowfish”); cipher.init(Cipher.DECRYPT_MODE, key); byte[] decrypted = cipher.doFinal(encryptedString.getBytes()); decryptedString = new String(decrypted, Charset.forName(“UTF-8”)); } [ catch Exceptions … ] 我得到一个例外: Exception. javax.crypto.IllegalBlockSizeException: Input length must be multiple of 8 when decrypting […]

使用Blowfish错误进行加密和解密 – 使用填充密码解密时,输入长度必须是8的倍数

我能够加密数据但是在解密时我收到以下错误: 错误 HTTP Status 500 – Request processing failed; nested exception is javax.crypto.IllegalBlockSizeException: Input length must be multiple of 8 when decrypting with padded cipher org.springframework.web.util.NestedServletException: Request processing failed; nested exception is javax.crypto.IllegalBlockSizeException: Input length must be multiple of 8 when decrypting with padded cipher org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:894) org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:778) javax.servlet.http.HttpServlet.service(HttpServlet.java:621) javax.servlet.http.HttpServlet.service(HttpServlet.java:728) 这是我的加密和解密代码 //secret key 8 private static […]

使用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 […]