赞
踩
des为块加密算法,数据长度必须为8的倍数,密钥长度为8:
- #include <stdlib.h>
- #include <stdio.h>
- #include <string.h>
- #include <rpc/des_crypt.h>
- int main(int argc, char** argv){
- char c = '\x8';
- printf("%c\n",'\x8');//\转义符后面三位数表示8进制如\101为65,\x8则为十六进制,\95则为十制
- char data[4096]= "abcdefghijklmnopqrstuVW000000000";//des 加密,数据一定要是8的倍数,不补齐,密后做取舍
-
- //we must fix the data to a multiple of 8...
-
- char key[8] = "12345678";
- char key2[8] = "12345678";
- des_setparity(key);
- ecb_crypt(key,data,strlen(data),DES_ENCRYPT);
- printf("%s\n",data);
-
- des_setparity(key2);
- ecb_crypt(key,data,strlen(data),DES_DECRYPT);
- printf("%s\n",data);
-
- return 0;
- }
- [xxx@localhost code]$ gcc -g -lcrypt destest.c
- [xxx@localhost code]$ ./a.out
- .Ck玫??9.PhQg?.?j}R.O9
- abcdefghijklmnopqrstuVW000000000
- [xxx@localhost code]$
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。