Module: EdgecastToken

Defined in:
lib/edgecast_token.rb,
lib/edgecast_token/version.rb,
ext/edgecast_token/edgecast_token.c

Constant Summary collapse

VERSION =
"1.0.2"

Class Method Summary collapse

Class Method Details

.encrypt(k, s) ⇒ Object



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);
}

.generate(key, input) ⇒ Object



5
6
7
8
# File 'lib/edgecast_token.rb', line 5

def self.generate(key, input)
  input = "ec_secure=%03d&%s" % [input.length + 14, input]
  encrypt(key, input)
end