- 論壇徽章:
- 0
|
本帖最后由 huxk 于 2010-07-26 09:25 編輯
現(xiàn)在我要使用 DES_ncbc_encrypt 加密報文,密鑰需要動態(tài)生成
開始使用 DES_random_key 這個函數(shù) 這個函數(shù)可用 而且也不會報 weak key
但看到OPENSSL作者的注釋【見下面】 我使用- void des_key_gen(const char *str,DES_cblock *deskey)
- {
- unsigned char b[16] = {0};
- unsigned char *out = &(*deskey)[0];
- MD5(str,strlen(str),b);
- memcpy(out,b,8);
- }
復制代碼 函數(shù)來產生KEY 但 DES_set_key_checked 函數(shù)檢查時報weak key
有人這樣搞過么?或者大家動態(tài)生成DES密鑰用什么算法好?不吝賜教。- 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.- void des_random_seed( des_cblock key);
復制代碼 This routine sets a starting point for des_random_key().- 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. |
|