Heim  >  Artikel  >  Backend-Entwicklung  >  javascript - aes128加密一些相关问题

javascript - aes128加密一些相关问题

WBOY
WBOYOriginal
2016-08-04 09:21:431245Durchsuche

class aes {

<code>const KEY = "625202f9149e061d";
const IV = "5efd3f6060e20330";

/**</code>
    • pkcs7补码

    • @param string $string 明文

    • @param int $blocksize Blocksize , 以 byte 为单位

    • @return String
      */

    1. function addPkcs7Padding($string, $blocksize = 32) {

      <code>   $len = strlen($string); //取得字符串长度
         $pad = $blocksize - ($len % $blocksize); //取得补码的长度
         $string .= str_repeat(chr($pad), $pad); //用ASCII码为补码长度的字符, 补足最后一段
         return $string;</code>

      }

    2. aes128cbcEncrypt($str, $iv = self::IV, $key = self::KEY) { // $this->addPkcs7Padding($str,16)

      <code>   $base = (mcrypt_encrypt(MCRYPT_RIJNDAEL_128, $key, $this->addPkcs7Padding($str, 16), MCRYPT_MODE_CBC, $iv));
         return $this->strToHex($base);</code>

      }

    3. strToHex($string) {//字符串转十六进制

      <code>   $hex = "";
         $tmp = "";
         for ($i = 0; $i </code>

      }
      aes加密 在网上找的代码有PHP 和 android 的 来位好心人讲讲$aes = new aes(); $aes->aes128cbcEncrypt('token');这个加密过程的每一步呗 或者帮忙写一份对应的js版本的 = =

    回复内容:

    class aes {

    <code>const KEY = "625202f9149e061d";
    const IV = "5efd3f6060e20330";
    
    /**</code>
    • pkcs7补码

    • @param string $string 明文

    • @param int $blocksize Blocksize , 以 byte 为单位

    • @return String
      */

    1. function addPkcs7Padding($string, $blocksize = 32) {

      <code>   $len = strlen($string); //取得字符串长度
         $pad = $blocksize - ($len % $blocksize); //取得补码的长度
         $string .= str_repeat(chr($pad), $pad); //用ASCII码为补码长度的字符, 补足最后一段
         return $string;</code>

      }

    2. aes128cbcEncrypt($str, $iv = self::IV, $key = self::KEY) { // $this->addPkcs7Padding($str,16)

      <code>   $base = (mcrypt_encrypt(MCRYPT_RIJNDAEL_128, $key, $this->addPkcs7Padding($str, 16), MCRYPT_MODE_CBC, $iv));
         return $this->strToHex($base);</code>

      }

    3. strToHex($string) {//字符串转十六进制

      <code>   $hex = "";
         $tmp = "";
         for ($i = 0; $i </code>

      }
      aes加密 在网上找的代码有PHP 和 android 的 来位好心人讲讲$aes = new aes(); $aes->aes128cbcEncrypt('token');这个加密过程的每一步呗 或者帮忙写一份对应的js版本的 = =

    说起来挺复杂的,你看看这个链接吧。
    http://yinghuayuan8866.blog.163.com/blog/static/2245702720121225658625/

    Stellungnahme:
    Der Inhalt dieses Artikels wird freiwillig von Internetnutzern beigesteuert und das Urheberrecht liegt beim ursprünglichen Autor. Diese Website übernimmt keine entsprechende rechtliche Verantwortung. Wenn Sie Inhalte finden, bei denen der Verdacht eines Plagiats oder einer Rechtsverletzung besteht, wenden Sie sich bitte an admin@php.cn