R1We4y0JRP5w06Z8tUBPAw==
先看 https://code.google.com/p/slowaes/source/browse/trunk/js/cryptoHelpers.js?r=33 的 generateSharedKey 怎麼產生的
1 2 3 4 5 6 7 8 9 | generateSharedKey: function (len) { if (len === null ) len = 16; var key = []; for ( var i = 0; i < len*2; i++) key.push( this .getRandom(0,255)); return key; } |
使用 cryptoHelpers.js 對他做處理,觀察各個型態的內容
1 2 3 4 5 | // need include cryptoHelpers.js var base64 = 'R1We4y0JRP5w06Z8tUBPAw==' ; console.log(cryptoHelpers.base64.decode(base64)); // base64 decode => byte array console.log(cryptoHelpers.convertByteArrayToString(cryptoHelpers.base64.decode(base64))); // to string console.log(cryptoHelpers.toHex(cryptoHelpers.base64.decode(base64))); // to hex |
結果:
cryptoHelpers.base64.decode(base64):[71, 85, 158, 227, 45, 9, 68, 254, 112, 211, 166, 124, 181, 64, 79, 3]
cryptoHelpers.convertByteArrayToString(cryptoHelpers.base64.decode(base64)):GUžã- DþpÓ¦|µ@O
cryptoHelpers.toHex(cryptoHelpers.base64.decode(base64)):47559ee32d0944fe70d3a67cb5404f03
使用PHP處理
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 | $iv = 'R1We4y0JRP5w06Z8tUBPAw==' ; echo " base64_decode (\ $iv ):". base64_decode ( $iv ); // base64 decode => binary string $iv64 = base64_decode ( $iv ); echo " strlen (\ $iv64 ):". strlen ( $iv64 ); // 長度16 echo " pack( 'H*' , bin2hex(\ $iv64 )):".pack( 'H*' , bin2hex( $iv64 )); // 與base64_decode($iv)結果相同 echo " bin2hex(\ $iv64 ):".bin2hex( $iv64 ); // to hex // to bytes array for ( $i =0; $i < strlen ( $iv64 ); $i ++) { $data [] = ord( substr ( $iv64 , $i ,1)); // 使用ord將字元轉成int } echo "<pre>\$data:" ; print_r( $data ); echo "</pre> "; |
結果:
base64_decode($iv):GU��- D�pӦ|�@O
strlen($iv64):16
pack('H*', bin2hex($iv64)):GU��- D�pӦ|�@O
bin2hex($iv64):47559ee32d0944fe70d3a67cb5404f03
$data:Array
(
[0] => 71
[1] => 85
[2] => 158
[3] => 227
[4] => 45
[5] => 9
[6] => 68
[7] => 254
[8] => 112
[9] => 211
[10] => 166
[11] => 124
[12] => 181
[13] => 64
[14] => 79
[15] => 3
)
還可以去 Unicode/UTF-8-character table 做字元最後的檢查
http://dev.networkerror.org/utf8/?start=0&end=255&cols=4&search=&show_uni_int=on&show_uni_hex=on&show_html_ent=on&show_raw_hex=on&show_raw_bin=on 0-255 的 Unicode Number (int) / Unicode Number (hex) / Char
http://www.scarfboy.com/coding/unicode-tool?s=000047 以hex 搜尋字元
http://stackoverflow.com/questions/11044802/php-hex-and-binary PHP Hex and Binary
沒有留言:
張貼留言