mes01 / js-mcrypt Goto Github PK
View Code? Open in Web Editor NEWAutomatically exported from code.google.com/p/js-mcrypt
Automatically exported from code.google.com/p/js-mcrypt
Hi,
do you integrate Twofish?
http://ats.oka.nu/titaniumcore/js/crypto/Cipher.sample.html
This sample works for me with mcrypt.
Here my PHP Code:
**************
<?php
/**
* @author Josef Fröhle
* @copyright 2012
*/
$iv_size = mcrypt_get_iv_size(MCRYPT_TWOFISH, MCRYPT_MODE_CBC);
$iv = mcrypt_create_iv($iv_size, MCRYPT_RAND);
$key = base64_decode('IDJkKkhBcyxWKDdWMzpgcjU3Vj4sWylsSStORkclfWM=');
$text = "Meet me at 11 o'clock behind the monument.";
echo base64_encode($key) . "\r\n";
$crypttext = mcrypt_encrypt(MCRYPT_TWOFISH, $key, $text, MCRYPT_MODE_CBC, $iv);
echo base64_encode($iv.$crypttext) . "\r\n";
$text = "reSz4nYwvUn2bCivKpNxRcausJ71JQHsGvoIKUc2Nvdl+nUw
OtHPPV2sqU7TyS+tg1eBeuxVzf6nvbn3J9yWlA==";
$text_enc = base64_decode($text);
$iv = substr($text_enc,0,16);
echo strlen($iv) . "\r\n";
$text = substr($text_enc,16);
$crypttext = mcrypt_decrypt(MCRYPT_TWOFISH, $key, $text, MCRYPT_MODE_CBC, $iv);
echo $crypttext;
?>
Original issue reported on code.google.com by [email protected]
on 12 Dec 2012 at 8:57
The following code (in mcrypt.js) causes an error in IE8, and prevents the
mcrypt library from loading.
var ciphers={ // block size, key size
"rijndael-128" :[ 16, 32],
"rijndael-192" :[ 24, 32],
"rijndael-256" :[ 32, 32],
"serpent" :[ 16, 32],
}
The issue is the comma at the end of the "serpent" line. FF and Chrome ignore
this syntax error and work correctly.
Original issue reported on code.google.com by [email protected]
on 17 Sep 2013 at 1:33
The Rijndael key padding used in mcrypt.js always pads the encryption key with
0's (null) up to 32 bytes, but PHP's mcrypt functions pad the key up to the
nearest valid key length (16, 24, or 32 bytes).
PHP exmaple:
<?php
//15 byte key
echo bin2hex(mcrypt_encrypt(MCRYPT_RIJNDAEL_128,
hex2bin("387498719817984798740000000000"), "test string to encrypt",
MCRYPT_MODE_ECB))."\n";
//16 byte key
echo bin2hex(mcrypt_encrypt(MCRYPT_RIJNDAEL_128,
hex2bin("38749871981798479874000000000000"), "test string to encrypt",
MCRYPT_MODE_ECB))."\n";
//17 byte key
echo bin2hex(mcrypt_encrypt(MCRYPT_RIJNDAEL_128,
hex2bin("3874987198179847987400000000000000"), "test string to encrypt",
MCRYPT_MODE_ECB))."\n";
//23 byte key
echo bin2hex(mcrypt_encrypt(MCRYPT_RIJNDAEL_128,
hex2bin("3874987198179847987400000000000000000000000000"), "test string to
encrypt", MCRYPT_MODE_ECB))."\n";
//24 byte key
echo bin2hex(mcrypt_encrypt(MCRYPT_RIJNDAEL_128,
hex2bin("387498719817984798740000000000000000000000000000"), "test string to
encrypt", MCRYPT_MODE_ECB))."\n";
//25 byte key
echo bin2hex(mcrypt_encrypt(MCRYPT_RIJNDAEL_128,
hex2bin("38749871981798479874000000000000000000000000000000"), "test string to
encrypt", MCRYPT_MODE_ECB))."\n";
?>
Output:
e544da48ce56ace9b74e7267cecc867bf87b275202419a5ab4ce2a59ab63c75c
e544da48ce56ace9b74e7267cecc867bf87b275202419a5ab4ce2a59ab63c75c
ef4c7f8811e758b6c9b0955e91163d8850e0259979571ef0f1b3a5417b448699
ef4c7f8811e758b6c9b0955e91163d8850e0259979571ef0f1b3a5417b448699
ef4c7f8811e758b6c9b0955e91163d8850e0259979571ef0f1b3a5417b448699
d49d2edc6937eb50765a508d2d4b6b74d4fc2851f41c81e733a7fe5fc0ed550f
This padding behavior occurs regardless of the rijndael algorithm (128 vs 192
vs 256) and ragardless of the block cipher mode (ECB vs CBC).
Tested on PHP 5.0.4 through 5.5.0.
Original issue reported on code.google.com by [email protected]
on 17 Sep 2013 at 1:57
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.