admin管理员组文章数量:1391836
Is there any JavaScript libs that lets you encrypt and decrypt 256 bit AES the way you do it with mcrypt in PHP (and get the same result of course)? I want to give it a variable-length message and a 32 chars key. All libs I find wants fixed-length blocks of cleartext and byte-arrays of keys.
This is how it's done in PHP:
$iv_size = mcrypt_get_iv_size(MCRYPT_RIJNDAEL_256, MCRYPT_MODE_ECB);
$iv = mcrypt_create_iv($iv_size, MCRYPT_RAND);
echo mcrypt_encrypt(MCRYPT_RIJNDAEL_256, "32 CHARS THAT REPRESENT MY KEY!!", "hello", MCRYPT_MODE_ECB, $iv);
Is there any JavaScript libs that lets you encrypt and decrypt 256 bit AES the way you do it with mcrypt in PHP (and get the same result of course)? I want to give it a variable-length message and a 32 chars key. All libs I find wants fixed-length blocks of cleartext and byte-arrays of keys.
This is how it's done in PHP:
$iv_size = mcrypt_get_iv_size(MCRYPT_RIJNDAEL_256, MCRYPT_MODE_ECB);
$iv = mcrypt_create_iv($iv_size, MCRYPT_RAND);
echo mcrypt_encrypt(MCRYPT_RIJNDAEL_256, "32 CHARS THAT REPRESENT MY KEY!!", "hello", MCRYPT_MODE_ECB, $iv);
Share
Improve this question
edited Oct 26, 2012 at 19:13
Peter O.
32.9k14 gold badges85 silver badges97 bronze badges
asked Aug 26, 2010 at 16:33
MartinMartin
5,30711 gold badges48 silver badges60 bronze badges
7
- 1 why would you want to encrypt using javascript? so that your encryption key could be seen by the world? – codeandcloud Commented Aug 26, 2010 at 16:36
- 2 ah don't worry about that, key is sent through https. – Martin Commented Aug 26, 2010 at 16:43
- 1 HTTPS or not, the users can still see the key in your JavaScript. So if I for instance visited your site with a HTTPS connection, I could see still the encryption key by just viewing at the source or using a tool such as Firebug. – Freyja Commented Aug 26, 2010 at 16:45
- I know i know. But it doesn't matter if the user can see it as long as noone else can. – Martin Commented Aug 26, 2010 at 16:51
- if you trust your user and the connection so much, why not letting HTTPS handle the security? – dcestari Commented Mar 2, 2011 at 21:46
1 Answer
Reset to default 6Yes! I made (the beginnings of) mcrypt for javascript. It doesn't have the exact same interface but it's similar. https://code.google./p/js-mcrypt/
本文标签: AES in JavaScript that matches PHP39s mcryptStack Overflow
版权声明:本文标题:AES in JavaScript that matches PHP's mcrypt - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744769391a2624244.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论