Java 等价于 C++ 加密

编程入门 行业动态 更新时间:2024-10-23 13:29:40
本文介绍了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++ 加密

本文发布于:2023-11-09 15:42:46,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1572765.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:Java

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!