我正在使用
我正在使用这些功能:
void algo_crypt(request_rec *r) {
char cookie[] = "VAR=USER123456";
unsigned char key_md5[16];
int len;
const_DES_cblock *input;
DES_cblock *output;
unsigned char in[BUFSIZE], out[BUFSIZE], back[BUFSIZE];
unsigned char *e = out;
DES_cblock key = "MyKey";
DES_cblock seed = {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10};
DES_key_schedule keysched;
memset(in, 0, sizeof(in));
memset(out, 0, sizeof(out));
memset(back, 0, sizeof(back));
DES_set_key((C_Block *)key, &keysched);
strcpy(in, cookie);
ap_log_rerror(APLOG_MARK, APLOG_ERR, 0, r, "Plaintext: [%s]\n", in);
DES_ecb_encrypt((C_Block *)cookie,(C_Block *)out, &keysched, DES_ENCRYPT);
am_cookie_set(r, out);
ap_log_rerror(APLOG_MARK, APLOG_ERR, 0, r, "Ciphertext out: %s", out);
while (*e)
ap_log_rerror(APLOG_MARK, APLOG_ERR, 0, r,
"algo_crypt [%02x] ", *e++);
}
void algo_decrypt(request_rec *r) {
unsigned char key_md5[16];
int len;
const_DES_cblock *input;
DES_cblock *output;
unsigned char in[BUFSIZE], back[BUFSIZE];
unsigned char out[] = {0xb8, 0xa8, 0xb0, 0x54, 0x40, 0x23, 0xd1, 0x25};
unsigned char *e = out;
DES_cblock key = "MyKey";
DES_key_schedule keysched;
memset(back, 0, sizeof(back));
DES_set_key((C_Block *)key, &keysched);
char *mycookie = am_cookie_get(r);
DES_ecb_encrypt((C_Block *)mycookie, (C_Block *)back, &keysched, DES_DECRYPT);
ap_log_rerror(APLOG_MARK, APLOG_ERR, 0, r, "Decrypted Text: [%s]\n", back);
}
但打印结果显示:
Decrypted Text: [VAR=USER]\n
我正在使用openssl、C,我正在使用ubuntu开发Apache