tag:blogger.com,1999:blog-822738186956251465.post7478684147368828363..comments2023-11-09T00:23:18.101-05:00Comments on Brent's Tech Ramblings: AES encryption and decryption in RubyBrenthttp://www.blogger.com/profile/17023647333704400692noreply@blogger.comBlogger11125tag:blogger.com,1999:blog-822738186956251465.post-39834629986652642032010-06-03T05:08:06.692-04:002010-06-03T05:08:06.692-04:00ok i found ... it has to be blob (:binary)for mysq...ok i found ... it has to be blob (:binary)<br><br>for mysqlAlexeyhttp://www.blogger.com/profile/01888820688161272210noreply@blogger.comtag:blogger.com,1999:blog-822738186956251465.post-61509743398100919922010-06-03T04:10:57.991-04:002010-06-03T04:10:57.991-04:00great article!how do i store encrypted string into...great article!<br><br>how do i store encrypted string into database ?<br>I have:<br>Mysql::Error: Incorrect string value: '\xDF\xF0\xCF\xE7\x1A\xDB...' for column 'email' at row 1:<br>UPDATE `orders` SET `email` = '▀Ё╧ч\Z█n~╒q+eХ┤a╡' .....<br><br>What type of column it has to be ?Alexeyhttp://www.blogger.com/profile/01888820688161272210noreply@blogger.comtag:blogger.com,1999:blog-822738186956251465.post-44842253486157541122010-06-03T04:08:16.129-04:002010-06-03T04:08:16.129-04:00This comment has been removed by the author.This comment has been removed by the author.Alexeyhttp://www.blogger.com/profile/01888820688161272210noreply@blogger.comtag:blogger.com,1999:blog-822738186956251465.post-27545878531391851452010-05-03T13:35:03.362-04:002010-05-03T13:35:03.362-04:00Thank you for the code...Did you find a way to mak...Thank you for the code...<br>Did you find a way to make it work inside rails?0ahttp://0x0000000a.comnoreply@blogger.comtag:blogger.com,1999:blog-822738186956251465.post-7358122904731423872009-11-16T09:31:11.551-05:002009-11-16T09:31:11.551-05:00Hmm, it doesn't look like that this is the pro...Hmm, it doesn't look like that this is the problem because as long as I run it outside the Rails env. it works fine and returns:<br>"\354\025#\300!\350'ZE\310\245I\2738\n-"<br><br>Inside Rails it doesn't work.Anonymousnoreply@blogger.comtag:blogger.com,1999:blog-822738186956251465.post-16142863115174168012009-11-15T12:52:58.898-05:002009-11-15T12:52:58.898-05:00The difference might be because your key and IV le...The difference might be because your key and IV lengths are not correct. The second parameter is the key, which should be 32 bytes/characters long for AES-256. The text string that you have for that is longer than 32 characters. The third parameter is the IV (initialization vector) which should be 16 bytes/characters long, and what you are passing in is longer than 16 characters. Try to cut those two parameters down to 32 and 16 characters and see if you get the same results.Brenthttp://www.blogger.com/profile/17023647333704400692noreply@blogger.comtag:blogger.com,1999:blog-822738186956251465.post-14255130686807120422009-11-15T12:33:00.416-05:002009-11-15T12:33:00.416-05:00That's a nice script and it works for me as lo...That's a nice script and it works for me as long as i run it in the terminal via irb on my mac. But when I try to implement this in my Rails App in /lib as a module and than call it from a Controller it returns things like "PG)??_Q?Ф???" <br><br>My code to run it looks like that:<br><br>class XY < ApplicationController<br>include Aescrypt<br> def index<br> puts Aescrypt.encrypt("Hehe", "Blalalalalalalalalalalalalalalalalalalalalalalalalal" , "jahdsfjhgdhjgdsjkhgjdfgajdhfhdagf", "AES-256-CBC")<br> end<br>end<br><br>in the terminal it returns <br><br>F???EMq??'?l%<br><br>do you have any idea?<br>Thx a lot.Anonymousnoreply@blogger.comtag:blogger.com,1999:blog-822738186956251465.post-28450232784564890432009-09-25T18:36:23.491-04:002009-09-25T18:36:23.491-04:00When I try using this module, I always get the err...When I try using this module, I always get the error "OpenSSL::CipherError: wrong final block length" when trying to decrypt. Example below:<br><br>AESCrypt.encrypt("tester","blahblahasdfasdfasdfasdfasdfasdf",nil,"AES-256-CBC")<br><br>AESCrypt.decrypt("}\206\213\237x?Kl\002x9?","blahblahasdfasdfasdfasdfasdfasdf",nil,"AES-256-CBC")<br>OpenSSL::CipherError: wrong final block length<br><br>I am pretty uninformed on this topic, so any help is greatly appreciated...wkapastinhttp://www.blogger.com/profile/10072903362884892843noreply@blogger.comtag:blogger.com,1999:blog-822738186956251465.post-41222955828569660242009-08-03T10:19:46.990-04:002009-08-03T10:19:46.990-04:00Thanks a lot for this code. Really usefulThanks a lot for this code. Really usefuldanimatahttp://www.blogger.com/profile/01415384092221844817noreply@blogger.comtag:blogger.com,1999:blog-822738186956251465.post-42026271040446995572009-02-10T14:05:00.000-05:002009-02-10T14:05:00.000-05:00Well - if you are worried about decrypting just a ...Well - if you are worried about decrypting just a single field, you can override the accessor methods.<br><br>def value=(val)<br> write_attribute(:value,encrypt(val))<br>end<br>def value<br> decrypt(read_attribute(:value))<br>endAnonymousnoreply@blogger.comtag:blogger.com,1999:blog-822738186956251465.post-12362239292721656902009-01-22T09:25:00.000-05:002009-01-22T09:25:00.000-05:00great post, I am trying to get rails to do the enc...great post, I am trying to get rails to do the encryption/decryption for me so i can just use the variable in the controller. It is easy to encrypt with a before_save filter, but how can we decrypt it after a select statement?ryanhttp://www.blogger.com/profile/14644299518115678984noreply@blogger.com