pkcs5_pad 补码算法

补码前的数据:b31d2458000000000000865067022840600001
补码后的数据:b31d24580000000000008650670228406000010d0d0d0d0d0d0d0d0d0d0d0d0d

// pkcs5_pad 补码算法

private static function pkcs5_pad($text, $blocksize){   
     $pad = $blocksize - (strlen($text) % $blocksize);   
     return $text . str_repeat(chr($pad), $pad);
}

// 这段代码有问题

public static function remove_pkcs_pad($decrypted)
{
    $dec_s = strlen($decrypted);
    $padding = ord($decrypted[ $dec_s - 1 ]);
    $decrypted = substr($decrypted, 0, - $padding);
    return $decrypted;
}

// 该段代码需要验证

public function remove_pkcs_pad2() 
{
        $complement = substr($decrypted_hex, strlen($decrypted_hex) - 2, 2);
        $complement = base_convert($complement, 16, 10);
        if ($complement < strlen($decrypted_hex)) {   
            $decrypted_hex = substr($decrypted_hex, 0, -1 * $complement * 2);
        }
}

你可能感兴趣的:(pkcs5_pad 补码算法)