我有以下用于创建AES-128密码的Java代码,其中key和iv都基于相同的密码短语。
Cipher cipher = Cipher.getInstance("AES/CBC/PKCS5Padding");
byte[] keyBytes = new byte[16];
byte[] b = passphare.getBytes("UTF-8");
int len = b.length;
if (len > keyBytes.length) {
len = keyBytes.length;
}
System.arraycopy(b, 0, ke
我使用的是AES 256 CBC。我有32个字节的IV。但是当我运行它时,它显示了一个异常,如下所示:
Exception in thread "main" java.lang.RuntimeException: java.security.InvalidAlgorithmParameterException: Wrong IV length: must be 16 bytes long
at com.abc.aes265cbc.AESUtil.decrypt(AESUtil.java:50)
at com.abc.aes265cbc.Security.main
我编写了两个函数来解密和加密C#和Javascript中的消息,但是我也需要它,而且我无法让它像以前的那样工作。
JS加密方法:
this.aesEncrypt = function (encryptedMessage) {
var key = CryptoJS.enc.Utf8.parse("xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx");
var initialVector = CryptoJS.enc.Utf8.parse("xxxxxxxxxxxxxxxx");
var encryptedText = Cry
我试图在C++中使用CryptoAPI加密,并使用SunJCE解密Java。我已经得到了RSA密钥来工作--并在一个测试字符串上验证了。然而,我的AES密钥不起作用--我得到了javax.crypto.BadPaddingException: Given final block not properly padded。
C++加密:
// init and gen key
HCRYPTPROV provider;
CryptAcquireContext(&provider, NULL, MS_ENH_RSA_AES_PROV, PROV_RSA_AES, CRYPT_VERIFYCON
我正在尝试解密java中使用CryptoJS加密的文本。我在其他帖子上读到过,它们使用不同的默认模式和填充,所以我将它们都设置为使用aes/cbc/nopadding.在java中我不再得到异常,但是在解密过程中我得到了乱码输出。
加密(JS):
var parsedLogin = JSON.parse(login);
var publicKey = "abcdefghijklmnio";
var publiciv = "abcdefghijklmnio";
var key = CryptoJS.enc.Hex.parse(publicKey);
var iv
我正在用VB.NET进行编码,需要用Ruby语言解码。我的VB.NET加密类如下所示:
Private Class Encryptor
Private symmetricKey As System.Security.Cryptography.RijndaelManaged
Private iVector As Byte()
Private Key As Byte()
Public Function encrypt(ByVal data As String) As String
Try
我在AES /CBC/PKCS5中使用AES,并在Java中添加了以下加密和解密代码部分:
cipher.init(Cipher.ENCRYPT_MODE, keySpec, new IvParameterSpec(IV1));
cipher.init(Cipher.DECRYPT_MODE, keySpec, new IvParameterSpec(IV2));
其中IV1和IV2是随机生成的16字节初始化向量。正如您所看到的,加密和解密过程中的初始化向量是不同的。这将导致解密消息的字节紧跟在前16个字节之后,例如消息:
Enter your message here...
变成了
****