- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在编写一个隐写术系统,该系统对图像中的文本进行加密 - 我决定在将文本嵌入图片中之前也对文本进行加密。隐写术算法适用于字符串输入/输出。
由于我的突发奇想,我一直在尝试使用 DES 和 AES 算法,但遇到了上面的异常。我将展示 AES 算法的加密/解密方法:
public static byte[] encryptText(String plainText,SecretKey secKey) throws Exception{
// AES defaults to AES/ECB/PKCS5Padding in Java 7
Cipher aesCipher = Cipher.getInstance("AES");
aesCipher.init(Cipher.ENCRYPT_MODE, secKey);
byte[] byteCipherText = aesCipher.doFinal(plainText.getBytes());
return byteCipherText;}
public static String decryptText(byte[] byteCipherText, SecretKey secKey) throws Exception {
// AES defaults to AES/ECB/PKCS5Padding in Java 7
Cipher aesCipher = Cipher.getInstance("AES");
aesCipher.init(Cipher.DECRYPT_MODE, secKey);
byte[] bytePlainText = aesCipher.doFinal(byteCipherText);
return new String(bytePlainText);
}
这是调用(加密端):
//sending the text to encrypt using AES algorithm
byte[] cipherText = new AES_Algorithm().encrypt(messageDesc.getText(), key);
//converting into a String to encrypt using Steganography
newStringtoEncrypt = new String (cipherText);
这是调用(解密方面) - 异常(exception):
//AES encrypted String after the Steganography's decryption
String decMessage = dec.decode(path, name);
//converting the String to byte []
byte [] byteArray = decMessage.getBytes();
try{
//HERE IS WHERE I GET THE EXCEPTION
//sending the byte array to decryption
String original = AES_Algorithm().decrypt(byteArray, key);
问题出在哪里?
键和字节数组都很相似(我通过打印序列进行了检查) - 但我被告知我不能使用 getBytes()
来从字符串转换当我打算使用 AES/DES
解密算法时,转换为 byteArray
。
最佳答案
加密的输出是二进制的,您不能像在此代码中那样将其转换为 String
:
byte[] cipherText = new AES_Algorithm().encrypt(messageDesc.getText(), key);
//converting into a String to encrypt using Steganography
newStringtoEncrypt = new String (cipherText);
如果您需要将加密数据作为String
,则需要以某种方式对其进行编码,例如通过 base64encoding或通过 hexEncoding
关于java - 无法克服 javax.crypto.BadPaddingException,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37457236/
我正在尝试更新一些较旧的代码以消除警告。我已经升级了一些使用加密模块的代码。然而,webpack 5.88.2没有识别新的语法。我的新导入内容如下所示:。完整的错误如下所示。这表明我可能需要另一个插件
是否有任何 C 或 C++ 函数可以产生与此 python 代码相同的输出(SHA512 with salt)? import crypt; crypt.crypt('test', '$6$Salte
我正在开发一个使用 Crypto++ 使用 RSA 加密一些数据的项目。 这是我的 Crypto++ 代码: string plain = "Text123", encoded, cipher; st
收到错误,因为 require 不是一个函数,尝试在 typescript 组件中使用加密 js 函数 // Load modules 'use strict'; var Crypto = requi
我正在尝试将下面的java代码转换为nodejs。 public static String encrypt(String accessToken) throws Exception {
我有一个旨在在 Node.js 中使用的签名方法,但我想使用 crypto-js 在客户端实现它。它应该可以在最新的 Chrome 版本中运行。 我尝试遵循以下一些答案:Decode a Base64
我想知道 Crypto.Signature.PKCS1_v1_5 和 Crypto.Signature.pkcs1_15 有什么区别? 在documentation他们使用此函数 Crypto.Sig
我们有一个使用 Crypto++ 库的 ECC 部分的 C++ 解决方案,但必须转移到 .NET 解决方案。由于 Microsoft 的 ECC 代码的文档最少,我目前正在试验文档最少的 Bouncy
我在验证 Web Crypto API 创建的签名时遇到问题。 这是我用来在浏览器中生成 RSA key 的代码: let keys; const generateKeys = async () =>
嗨,所以我有一个运行 Crypto 的服务器,它工作得很好。我使用 electrojs 作为客户端,并且加密应该内置到 Node 中。当我尝试使用该模块时,它返回“crypto.scryptSync
使用 Apple 的 Common Crypto 和 Crypto++ 使用相同的 key 加密相同的文件(二进制数据)时,我得到了不同的结果。我使用的算法是 AES。 这是使用 Common Cry
如何存储 crypto.createHash('sha1') 的当前状态(在它被 hash.update(buffer) 填充后)以在另一个地方使用它http请求可能发生在node.js的不同进程?
我正在使用 NodeJS 的捆绑 crypto服务器端的 SHA256 哈希模块。在客户端,我使用一个名为 Crypto-JS 的 javascript 库. 我将 SHA256 哈希值用于使用基于经
我想编写一个使用 linux crypto-api 进行数字签名的 C 程序。不幸的是,我找不到关于 linux api 和 linux/crypto.h 中定义的函数的良好文档(谷歌搜索没有帮助,这
我正在尝试使用 JUNIT 在实际执行 AES 加密的方法中模拟 cipher.doFinal()。我在启动 JUNIT 测试用例时遇到异常 "Tried to access class javax.
您好,我在Liferay dxp项目中使用Paytm校验和依赖项 但我得到error :com.sun.crypto.provider.AESCipher$General cannot be cast
我正在尝试使用 crypto-js javascript 库加密数据,并尝试使用 Node 加密库在 Nodejs 端解密相同的加密文本。我正在使用 AES 256 加密算法和 CTR 模式,没有填充
我想了解 javax.crypto.Mac 之间的区别和 javax.crypto.Cipher 。这两个类看起来非常相似(它们具有相似的方法,但是这两个类并不互相继承)。 这两个类之间的根本区别是什
我正在尝试在设备上生成 SHA256 和 HmacSHA512 哈希值,不幸的是,该设备不支持标准 Node crypto 库。所以我正在调整代码以使用 CryptoJS 代替。但是,CryptoJS
我正在使用 Android FingerPrintManager API 并使用 KeyPairGenerator 创建 key 对,我想使用公钥加密密码,然后在用户通过输入 fingerPrint
我是一名优秀的程序员,十分优秀!