AES Encryption to Match PHP's Mcrypt Extension
2009-06-02 13:31
429 查看
Demonstrates how to match AES encryption results with PHP's mcrypt extension.
Please refer to this discussion about PHP AES Encryption. The code here matches the PHP mcrypt results on that page.
Download Chilkat .NET for 2.0 / 3.5 Framework
Download Chilkat .NET for 64-bit 2.0 / 3.5 Framework (x64)
Download Chilkat .NET for 1.0 / 1.1 Framework
Please refer to this discussion about PHP AES Encryption. The code here matches the PHP mcrypt results on that page.
Download Chilkat .NET for 2.0 / 3.5 Framework
Download Chilkat .NET for 64-bit 2.0 / 3.5 Framework (x64)
Download Chilkat .NET for 1.0 / 1.1 Framework
Chilkat.Crypt2 crypt = new Chilkat.Crypt2(); bool success; success = crypt.UnlockComponent("Anything for 30-day trial"); if (success != true) { MessageBox.Show("Crypt component unlock failed"); return; } // AES is also known as Rijndael. crypt.CryptAlgorithm = "aes"; // CipherMode may be "ecb" or "cbc" crypt.CipherMode = "cbc"; // KeyLength may be 128, 192, 256 crypt.KeyLength = 256; // Pad with NULL bytes (PHP pads with NULL bytes) crypt.PaddingScheme = 3; // EncodingMode specifies the encoding of the output for // encryption, and the input for decryption. // It may be "hex", "url", "base64", or "quoted-printable". crypt.EncodingMode = "hex"; string ivAscii; ivAscii = "1234567890123456"; crypt.SetEncodedIV(ivAscii,"ascii"); // The secret key must equal the size of the key. For // 256-bit encryption, the binary secret key is 32 bytes. // For 128-bit encryption, the binary secret key is 16 bytes. string keyAscii; keyAscii = "12345678901234561234567890123456"; crypt.SetEncodedKey(keyAscii,"ascii"); string plainText; plainText = "The quick brown fox jumped over the lazy dog"; string cipherText; cipherText = crypt.EncryptStringENC(plainText); MessageBox.Show(cipherText); // Do 128-bit AES encryption: crypt.KeyLength = 128; keyAscii = "1234567890123456"; crypt.SetEncodedKey(keyAscii,"ascii"); cipherText = crypt.EncryptStringENC(plainText); MessageBox.Show(cipherText); // ------- // Results // ------- // You may use these as test vectors for testing your AES implementations... // // ------------------------ // 256-bit key, CBC mode // ------------------------ // IV = '1234567890123456' // (hex: 31323334353637383930313233343536) // Key = '12345678901234561234567890123456' // (hex: 3132333435363738393031323334353631323334353637383930313233343536) // PlainText: // 'The quick brown fox jumped over the lazy dog' // CipherText(hex): // 2fddc3abec692e1572d9b7d629172a05caf230bc7c8fd2d26ccfd65f9c54526984f7cb1c4326ef058cd7bee3967299e3 // // ------------------------ // 128-bit key, CBC mode // ------------------------ // IV = '1234567890123456' // (hex: 31323334353637383930313233343536) // Key = '1234567890123456' // (hex: 31323334353637383930313233343536) // PlainText: // 'The quick brown fox jumped over the lazy dog' // CipherText(hex): // f78176ae8dfe84578529208d30f446bbb29a64dc388b5c0b63140a4f316b3f341fe7d3b1a3cc5113c81ef8dd714a1c99
相关文章推荐
- Unable to load dynamic library 'c:/php/extensions/php_mssql.dll'
- PHP Warning: PHP Startup: Unable to load dynamic library '/usr/lib/php5/20121212/pdo_mysql.so' - /us
- PHP Warning: date() [function.date]: It is not safe to rely on the system's timezone
- git切换分支报错:error: pathspec 'origin/XXX' did not match any file(s) known to git.
- 【解决问题】'failed to open stream:Permission denied in......'在php出现情况总结
- 兔子-(PHP 5.3 and above) Please set 'request_order' ini value to include C,G and P (recommended: 'CGP'
- PHP操作RabbitMQ消息接收不到的问题【cannot publish to internal exchange 'push-apns' in vhost 'pushHost】
- Could not load extension from . The 'manifest_version' key must be present and set to 2 (without quo
- How to Install mcrypt for php on Mac OSX Lion 10.8 & 10.7 Development Server
- PHP 5.3.10 编译安装时出现 undefined reference to `libiconv' 错误的解决方法
- How To Fix – Mcrypt PHP extension required in Laravel on Mac OS X (No MAMP)
- tomcat启动的时候发现一个错误 Setting property 'debug' to '0' did not find a matchin
- Unable to find the socket transport 'ssl' - did you forget to enable it when you configured PHP?
- PHP Warning Unable to load dynamic library 'E:/lib/php-5.2.17/ext/php_mysqli.dll'
- PHP Warning: PHP Startup: Unable to load dynamic library './php_mysql.dll' - /xd5/xd2/xb2/xbb/xb5/xbd/xd6/xb8/xb6/xa8/xb5/xc4/x
- [Javascript] A function works like 'print_r()' in PHP to print out the details of an object for JS debugging
- PHP OpenSSL&Mcrypt实现AES加密
- Could not write to 'conf_global.php'
- Warning: PHP Startup: Unable to load dynamic library 'php/ext\php_pgsql.dll' - %1 不是有效的 Win32 应用程序
- Unable to load dynamic library 'f:\php\ext\php_redis.dll' - 找不到指定的模块。