AES 256加密/解密中的MySQL和Java互操作性
以下加密和解密在MySQL(AES-256-CBC)模式中正常工作,
SET block_encryption_mode = 'aes-256-cbc';
select
cast(
aes_decrypt(
from_base64('StThdNXA+CWvlg+of/heJQ=='),
sha2(concat('ssshhhhhhhhhhh!!','ENCRYPTION_KEY$&'),256),
'ssshhhhhhhhhhh!!'
)
as char);
select to_base64(aes_encrypt(
'test_value',
sha2(concat('ssshhhhhhhhhhh!!','ENCRYPTION_KEY$&'),256),
'ssshhhhhhhhhhh!!'
));
我试图解密在MySQL中加密的值,但没有运气。
以下是我的MySQL查询SHA256(SALT+KEY)中的关键,
select sha2(concat('ssshhhhhhhhhhh!!','ENCRYPTION_KEY$&'),256);
我可以在Java中获得相同的值:
Hashing.sha256().hashString("ssshhhhhhhhhhh!!ENCRYPTION_KEY$&", StandardCharsets.UTF_8).toString();
有没有一种自定义的方法可以使弹力城堡/其他API使用相同的秘密钥匙来解密?
The following encryption and decryption works fine in mysql (aes-256-cbc) mode
SET block_encryption_mode = 'aes-256-cbc';
select
cast(
aes_decrypt(
from_base64('StThdNXA+CWvlg+of/heJQ=='),
sha2(concat('ssshhhhhhhhhhh!!','ENCRYPTION_KEYamp;'),256),
'ssshhhhhhhhhhh!!'
)
as char);
select to_base64(aes_encrypt(
'test_value',
sha2(concat('ssshhhhhhhhhhh!!','ENCRYPTION_KEYamp;'),256),
'ssshhhhhhhhhhh!!'
));
I am trying to decrypt value that was encrypted in mysql but no luck.
The following is the key in my mysql query sha256(salt+key)
select sha2(concat('ssshhhhhhhhhhh!!','ENCRYPTION_KEYamp;'),256);
The same value I am able to get in java :
Hashing.sha256().hashString("ssshhhhhhhhhhh!!ENCRYPTION_KEYamp;", StandardCharsets.UTF_8).toString();
Is there a custom way I can make bouncy castle/other API use same secret key to decrypt ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
MySQL内部使用EVP_BYTESTOKEY的OPENSL算法用作推导函数。
mySQL加密和解密示例:
有一个jar支持此EVP_BYTESTOKEY密钥推导功能。
}
以这种方式互操作性!希望这可以帮助一个尝试做同样的人的人。
MySQL internally uses OpenSSL algorithm with EVP_BytesToKey as the derivation function. Check out this url
MySQL encrypt and decrypt sample:
There is a JAR that supports this EVP_BytesToKey key derivation function.
}
This way interoperability is achieved, finally ! Hope this helps someone who's trying to do the same.