Chinaunix

标题: 熟悉OPENSSL的请进 [打印本页]

作者: huxk    时间: 2010-07-25 15:04
标题: 熟悉OPENSSL的请进
本帖最后由 huxk 于 2010-07-26 09:25 编辑

现在我要使用 DES_ncbc_encrypt 加密报文,密钥需要动态生成
开始使用 DES_random_key 这个函数 这个函数可用 而且也不会报 weak key

但看到OPENSSL作者的注释【见下面】 我使用
  1. void des_key_gen(const char *str,DES_cblock *deskey)
  2.         {
  3.         unsigned char        b[16] = {0};
  4.         unsigned char *out = &(*deskey)[0];
  5.         MD5(str,strlen(str),b);
  6.         memcpy(out,b,8);
  7.         }
复制代码
函数来产生KEY    但 DES_set_key_checked 函数检查时报weak key

有人这样搞过么?或者大家动态生成DES密钥用什么算法好?不吝赐教。
  1. void des_string_to_key( char *str, des_cblock *key);
复制代码
This function takes str and converts it into a DES key.  
I would recommend using MD5 instead and use the first 8 bytes of output.When I wrote the first version of these routines back in 1990, MD5 did not exist but I feel these routines are still sound.  This
routines is compatible with the one in MIT's libdes.
  1. void des_random_seed( des_cblock key);
复制代码
This routine sets a starting point for des_random_key().
  1. void des_random_key( des_cblock ret); This function return a random key.
复制代码
Make sure to 'seed' the random number generator (with des_random_seed()) before using this function.
I personally now use a MD5 based random number system.
作者: suavelee    时间: 2010-07-26 08:55
提示: 作者被禁止或删除 内容自动屏蔽
作者: huxk    时间: 2010-07-26 09:26
有人吗?呼叫 ....................
作者: bittertea    时间: 2010-07-26 12:36
1。自己生成密钥,然后调用des_set_key_unchecked

2。或者用PBE方式(PKCS#5)根据一个密码产生任意长度得密钥
作者: yahnn    时间: 2010-11-15 10:04
帮顶...




欢迎光临 Chinaunix (http://bbs.chinaunix.net/) Powered by Discuz! X3.2