From: Roland Schmitt Date: 2005-09-27T20:47:38+09:00 Subject: AW: How do I (really) encrypt a string in ruby? Hello, > -----Urspr�ngliche Nachricht----- > Von: ruby-talk-admin@ruby-lang.org > [mailto:ruby-talk-admin@ruby-lang.org] Im Auftrag von Michal Suchanek > Gesendet: Dienstag, 27. September 2005 13:09 > An: ruby-talk ML > Betreff: How do I (really) encrypt a string in ruby? > > Hello > > I find the ruby crypto very confusing. It looks like the > methods are dynamically generated, and carry no rdoc > documentation that would appear on ruby-doc. Yes, it is a sad, sad story... > I tried to look at the openssl samples supplied with ruby. > But they only show how to use a high level method which ... Example: require "openssl" include OpenSSL include Cipher cipher = Cipher.new("AES-256-CBC") key = cipher.random_key() iv = cipher.random_iv() #---- Encrypt text = "Hello, World!" cipher.encrypt(key,iv) cipher.key=key cipher.iv = iv e = cipher.update(text) e << cipher.final() puts("Encrypted text: " + e.to_s()) #---- Decrypt cipher = Cipher.new("AES-256-CBC") cipher.decrypt(key,iv) cipher.key = key cipher.iv = iv d = cipher.update(e) d << cipher.final() puts("Plain text: " + d.to_s()) Hope it helps, Roland