使用PHP组合c#WinRT加密/解密代码

时间:2015-12-24 10:25:40

标签: c# php encryption windows-runtime

我有这个WinRT代码:

  $params = array(
            'page'      => $page ,
            'limit'     => (!is_null($request->input('rows')) ? filter_var($request->input('rows'),FILTER_VALIDATE_INT) : static::$per_page ) ,
            'sort'      => $sort ,
            'order'     => $order,
            'params'    => $filter,
            'global'    => (isset($this->access['is_global']) ? $this->access['is_global'] : 0 )
        );
        // Get Query 
        $results = $this->model->getRows( $params );

我需要在PHP中使用它。我正在尝试在此代码中执行此操作,但这不一样:

public static string Encrypt(string Login)
    {
        var input = CryptographicBuffer.ConvertStringToBinary(Login, BinaryStringEncoding.Utf8);
        var BinKey = CryptographicBuffer.ConvertStringToBinary(Key, BinaryStringEncoding.Utf8);
        var BinIV = CryptographicBuffer.ConvertStringToBinary(IV, BinaryStringEncoding.Utf8);

        var Encryptor = SymmetricKeyAlgorithmProvider.OpenAlgorithm(SymmetricAlgorithmNames.AesCbcPkcs7);

        var SymmKey = Encryptor.CreateSymmetricKey(BinKey);

        var encrypted = CryptographicEngine.Encrypt(SymmKey, input, BinIV);

        return CryptographicBuffer.EncodeToBase64String(encrypted);
    }

    public static string Decrypt(string LoginToDecode)
    {
        var input = CryptographicBuffer.DecodeFromBase64String(LoginToDecode);
        var BinKey = CryptographicBuffer.ConvertStringToBinary(Key, BinaryStringEncoding.Utf8);
        var BinIV = CryptographicBuffer.ConvertStringToBinary(IV, BinaryStringEncoding.Utf8);

        var Decryptor = SymmetricKeyAlgorithmProvider.OpenAlgorithm(SymmetricAlgorithmNames.AesCbcPkcs7);

        var SymmKey = Decryptor.CreateSymmetricKey(BinKey);

        var Decrypted = CryptographicEngine.Decrypt(SymmKey, input, BinIV);

        return CryptographicBuffer.ConvertBinaryToString(BinaryStringEncoding.Utf8, Decrypted);
    }

function encryptRJ256($ key,$ iv,$ string_to_encrypt){     $ rtn = mcrypt_encrypt(MCRYPT_RIJNDAEL_128,$ key,$ string_to_encrypt,MCRYPT_MODE_CBC,$ iv);     $ rtn = base64_encode($ rtn);     返回(RTN $);}

例如,对于c#中的此输入:

  • Key =“lkirwf897 + 22#bbt”
  • IV =“741952hheeyy66#c”
  • password =“Asd”

我有“eSy8m8ygN7rtC80DMdGOUQ ==”。 我需要用PHP。

0 个答案:

没有答案