62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
|
# File 'ext/edgecast_token/edgecast_token.c', line 62
static VALUE ec_encrypt(VALUE self, VALUE k, VALUE s)
{
char *key = StringValueCStr(k);
char *string = StringValueCStr(s);
char encrypted[kMAX_TOKEN_LENGTH*4];
BF_KEY bf_key;
BF_set_key(&bf_key, strlen(key), key);
unsigned char ivec[32];
memset(ivec, '\0', 32);
int num=0;
cfb64_encrypt(string, encrypted, strlen(string), &bf_key, ivec, &num, BF_ENCRYPT);
// convert to hex string
char result[strlen(string) * 2];
char hex[3];
strcpy(result, "");
unsigned int i = 0;
for(i; i<strlen(string); i++)
{
sprintf(hex, "%02x", encrypted[i]&0xff);
strcat(result, hex);
}
return rb_str_new2(result);
}
|