Java 等价于 C++ 加密 [英] Java equivalent of C++ encryption

查看:23
本文介绍了Java 等价于 C++ 加密的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下用于加密的 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加密有关.但不确定什么是等价物.基本上我想要与 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 的书Network Security with 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).

一旦您知道需要做什么,使用标准的 javax.crypto 包在 Java 中编写代码应该不会有太大困难.

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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆