Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

crypto中加解密相关api的使用疑问 #26

Open
WankkoRee opened this issue Oct 4, 2023 · 0 comments
Open

crypto中加解密相关api的使用疑问 #26

WankkoRee opened this issue Oct 4, 2023 · 0 comments

Comments

@WankkoRee
Copy link

  • encrypt函数无法与decrypt函数自洽,如下代码将会报错。
const encrypt = crypto.encrypt("abcdefghijklmnop", "123", CRYPTO_AES, "AES/CBC/PKCS5Padding");
console.log(`encrypt = ${encrypt}`);

const decrypt = crypto.decrypt("abcdefghijklmnop", encrypt, CRYPTO_AES, "AES/CBC/PKCS5Padding");
console.log(`decrypt = ${decrypt}`);
encrypt = UtfTTy9RVgrhwzxMrAauQg==
JavaScript exception: JavaException: java.lang.NullPointerException: decryptAES(EncodeUtils.b…(), transformation, null) must not be null
  • encryptBytes函数无法与decryptBytes函数自洽,如下代码将会报错。
const encryptBytes = crypto.encryptBytes([0x61,0x62,0x63,0x64,0x65,0x66,0x67,0x68,0x69,0x6a,0x6b,0x6c,0x6d,0x6e,0x6f,0x70], [0x31,0x32,0x33], CRYPTO_AES, "AES/CBC/PKCS5Padding");
console.log(`encryptBytes = ${encryptBytes}`);

const decryptBytes = crypto.decryptBytes([0x61,0x62,0x63,0x64,0x65,0x66,0x67,0x68,0x69,0x6a,0x6b,0x6c,0x6d,0x6e,0x6f,0x70], encryptBytes, CRYPTO_AES, "AES/CBC/PKCS5Padding");
console.log(`decryptBytes = ${decryptBytes}`);
encryptBytes = [B@56effe6
JavaScript exception: JavaException: java.lang.NullPointerException: {
                Encryp…tion, null)
            } must not be null

在aes和des加密时,如果使用CBC或其他需要iv的操作,为什么不需要传入iv,jshook提供的这个方法默认iv是什么,是否应当提供一个iv传参?


rc4EncryptBytes函数无法与rc4DecryptBytes函数自洽,如下代码无法还原数据。且测试二次加密/二次解密无法实现RC4的对合性。是否是函数实现存在问题?

const rc4EncryptBytes = crypto.rc4EncryptBytes([0x61,0x62,0x63,0x64,0x65,0x66], [0x31,0x32,0x33,0x34,0x35,0x36,0x37,0x38]);
console.log(`rc4EncryptBytes = ${rc4EncryptBytes.map(v => v)}`);

const rc4DecryptBytes = crypto.rc4DecryptBytes([0x61,0x62,0x63,0x64,0x65,0x66], rc4EncryptBytes);
console.log(`rc4DecryptBytes = ${rc4DecryptBytes.map(v => v)}`);

const rc4EncryptBytesAgain = crypto.rc4EncryptBytes([0x61,0x62,0x63,0x64,0x65,0x66], rc4EncryptBytes); // RC4有对合性,理论上可以通过二次加密还原内容
console.log(`rc4EncryptBytesAgain = ${rc4EncryptBytesAgain.map(v => v)}`);

const rc4DecryptBytesAgain = crypto.rc4DecryptBytes([0x61,0x62,0x63,0x64,0x65,0x66], rc4DecryptBytes); // RC4有对合性,理论上可以通过二次解密还原内容
console.log(`rc4DecryptBytesAgain = ${rc4DecryptBytesAgain.map(v => v)}`);
rc4EncryptBytes = 50,32,-17,-115,31,50
rc4DecryptBytes = 34,-46,-6,44,33,-124
rc4EncryptBytesAgain = 60,-97,119,-70,94,-5
JavaScript exception: JavaException: java.lang.IllegalArgumentException: key must be between 1 and 256 bytes
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant