AES加密-Key代与OpenSSL的 [英] AES Encryption -Key Generation with OpenSSL

查看:334
本文介绍了AES加密-Key代与OpenSSL的的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

作为参考,作为延续到后:
<一href=\"http://stackoverflow.com/questions/5136279/how-to-use-openssl-to-decrypt-java-aes-encrypted-data\">how要使用OpenSSL解密的Java AES加密的数据?

As a reference and as continuation to the post: how to use OpenSSL to decrypt Java AES-encrypted data?

我有以下几个问题。

我使用OpenSSL库和编程℃,数据AES-CBC-128加密。
我给出任何输入的二进制数据,我有加密此。

I am using OpenSSL libs and programming in C for encrypting data in aes-cbc-128. I am given any input binary data and I have to encrypt this.

我知道Java有一个CipherParameters界面设置IV和KeyParameters了。

I learn that Java has a CipherParameters interface to set IV and KeyParameters too.

有没有一种方法来生成IV和使用OpenSSL的关键?总之何以在C程序中使用调用的OpenSSL随机数发生器用于这些目的。可以在此任你提供一些文档/例子/链接?

Is there a way to generate IV and a key using openSSL? In short how could one use in a C program to call the random generator of openSSL for these purposes. Can any of you provide some docs/examples/links on this?

感谢

推荐答案

这是AES密钥和对称加密的IV,只是bunchs随机字节。因此,任何加密的强随机数生成器会做的伎俩。 OpenSSL提供了这样一个随机数发生器(这本身无论操作系统提供,如 CryptGenRandom()在Windows或的/ dev /随机的/ dev / urandom的在Linux上)。该功能是 RAND_bytes()。因此,code是这样的:

An AES key, and an IV for symmetric encryption, are just bunchs of random bytes. So any cryptographically strong random number generator will do the trick. OpenSSL provides such a random number generator (which itself feeds on whatever the operating system provides, e.g. CryptGenRandom() on Windows or /dev/random and /dev/urandom on Linux). The function is RAND_bytes(). So the code would look like this:

#include <openssl/rand.h>

/* ... */
unsigned char key[16], iv[16];

if (!RAND_bytes(key, sizeof key)) {
    /* OpenSSL reports a failure, act accordingly */
}
if (!RAND_bytes(iv, sizeof iv)) {
    /* OpenSSL reports a failure, act accordingly */
}

这篇关于AES加密-Key代与OpenSSL的的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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