Java相当于C ++加密 [英] Java equivalent of C++ encryption
问题描述
我有以下用于加密的c ++代码片段:
I have this following snippet from c++ code that is used for encryption:
EVP_CIPHER_CTX ctx;
const EVP_CIPHER * cipher = EVP_des_ede3_cbc();
unsigned char iv[EVP_MAX_IV_LENGTH];
unsigned char key[EVP_MAX_KEY_LENGTH];
String seed;
_config->get_value("crypto_seed", &seed); // uses the seed value from pimp config.
if (seed.is_empty())
{
return false;
}
EVP_BytesToKey(cipher, EVP_sha1(),
(unsigned char *) 0, // no salt
reinterpret_cast<unsigned char *>(const_cast<char *>(seed.chars())), seed.length(),
1, // hash passphrase just once.
key, iv);
EVP_CIPHER_CTX_init(&ctx);
EVP_CipherInit_ex(&ctx, cipher, (ENGINE *) 0, key,
iv,
1); // encrypt
在java中相当于c ++加密是什么?
what s the equivalent of the c++ encryption in java?
我看到有 des
算法,那么我看到 sha1
。
I see there is des
algorithm, then i see sha1
.
这与openssl加密有关。新200新新新旗新新新200新200新新200新新新200新新200新新200新新200新新200新新200新新新新新新新新旗新旗新本质上我希望与c ++代码生成相同的输出。
This is related to openssl encryption. But not sure what is the equivalent. essentially i would like the same output as c++ code generates.
我询问相当于 EVP_CIPHER_CTX
或这里使用的加密名称是什么,所以我可以从那里拿走。
i m asking the what s the equivalent of EVP_CIPHER_CTX
or what s the name of the encrytion being used here so i can take it from there.
编辑:不要求任何人将代码转换为java,只是询问相应的包或类将执行相同的操作。
推荐答案
您正在转换的代码使用openssl库。它使用初始向量执行三重DES加密。您需要了解的第一件事就是它正在做什么(最好是为什么)。
The code you are converting from uses the openssl library. It carries out a triple-DES encryption using an Initial Vector. The first thing you need to understand is exactly what it's doing (and preferably why).
不幸的是,openssl文档并不是非常彻底(参见这里)...虽然O'Reilley的书籍网络安全与OpenSSL 是相当好一点(这有点过时了)。
Unfortunately the openssl documentation isn't terribly thorough (see here) ... though the O'Reilley book Network Security with OpenSSL is quite a bit better (it's a bit out of date, though).
一旦你知道需要做什么,你不应该在Java中编写很多困难使用标准的javax.crypto包。
Once you know what needs to be done, you shouldn't have much difficulty coding it in Java using the standard javax.crypto package.
这篇关于Java相当于C ++加密的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!