From: Michal Suchanek Date: 2005-09-27T20:08:47+09:00 Subject: How do I (really) encrypt a string in ruby? Hello I find the ruby crypto very confusing. It looks like the methods aredynamically generated, and carry no rdoc documentation that wouldappear on ruby-doc. I tried to look at the openssl samples supplied with ruby.But they only show how to use a high level method which - does not allow specifying ivec - makes the encrypted string longer than plain string (even forlenghts like 4K I would consider very well rounded) So the question is: how to make the equivalent of the following in ruby?I am not sure how the length is supposed to be rounded and how longthe ivec should be - there is no documentation for aes in the opensslman pages. The following program is supposed to read a file from stdin, encrypteach BUFLEN block with key specified in file testkey and ivecspecified in testiv, and output file of the same length (rounded toKLEN). Decrypt if an argument is specified.In ruby I could not specify the ivec, and the blocks would inflate slightly. #include #include #include #include #define BUFLEN 256#define KLEN 32#define KBITS 256 void main(int argc, char** argv) { AES_KEY ks; FILE * keyf = fopen("testkey","rb"); FILE * ivf = fopen("testiv","rb"); assert(keyf && ivf); char buf[BUFLEN]; char key [KLEN]; char iv [KLEN]; char civ [KLEN]; int res; int len; int way; res=fread(key, KLEN, 1, keyf); assert(res); res=fread(iv, KLEN, 1, ivf); assert(res); memcpy(civ, iv, KLEN); if(argc>1){ fprintf(stderr, "DECRYPT"); AES_set_decrypt_key(key, KBITS, &ks); way=AES_DECRYPT; }else{ fprintf(stderr, "ENCRYPT"); AES_set_encrypt_key(key, KBITS, &ks); way=AES_ENCRYPT; } while(len = fread(buf, 1, BUFLEN, stdin)){ if(len