相关疑难解决方法(0)

PHP加密和Windows解密

我被卡住了.似乎PHP完成的AES加密无法在Windows中解密.

PHP代码:

$encrypted = base64_encode(mcrypt_encrypt(MCRYPT_RIJNDAEL_128,"12345678", "test", MCRYPT_MODE_CBC));
Run Code Online (Sandbox Code Playgroud)

Windows代码:"s"具有从base64转换回来后由上述响应创建的字符串.

bool Decrypt(char* s,char* key,char* dest)
{
// Create the crypto provider context.
HCRYPTPROV hProvider = NULL;
if (!CryptAcquireContext(&hProvider,
    NULL,  // pszContainer = no named container
    MS_ENH_RSA_AES_PROV,  // pszProvider = default provider
    PROV_RSA_AES,
    0)) 
        return false;


// Construct the blob necessary for the key generation.
aes128keyBlob aes_blob128;

aes_blob128.header.bType = PLAINTEXTKEYBLOB;
aes_blob128.header.bVersion = CUR_BLOB_VERSION;
aes_blob128.header.reserved = 0;
aes_blob128.header.aiKeyAlg = CALG_AES_128;
aes_blob128.keySize = 16;
memcpy(aes_blob128.bytes, key, 16);

HCRYPTKEY hKey = NULL;
if (!CryptImportKey(hProvider,
    (BYTE*)(&aes_blob128),
    sizeof(aes_blob128), …
Run Code Online (Sandbox Code Playgroud)

php c++ encryption aes

14
推荐指数
1
解决办法
3193
查看次数

php md5算法,给出与c#相同的结果

我在C#中有一个散列算法,简而言之,它是:

string input = "asd";

System.Security.Cryptography.MD5 alg = System.Security.Cryptography.MD5.Create();
System.Text.UTF8Encoding enc = new System.Text.UTF8Encoding();


byte[] hash = alg.ComputeHash(enc.GetBytes(input));
string output = Convert.ToBase64String(hash);

// outputs:   eBVpbsvxyW5olLd5RW0zDg==
Console.WriteLine(output);
Run Code Online (Sandbox Code Playgroud)

现在我需要在php中复制这种行为,

$input = "asd";
$output = HashSomething($input);
echo $output;
Run Code Online (Sandbox Code Playgroud)

我怎样才能实现它?

我检查了

  • MD5
  • utf8_decode
  • 函数utf8_encode
  • BASE64_ENCODE
  • BASE64_DECODE
  • url_decode

但我注意到php md5最终没有得到== ...我错过了什么?

注意:我无法更改C#行为,因为它已经实现并且使用此算法将密码保存在我的数据库中.

php c# md5

8
推荐指数
2
解决办法
5422
查看次数

标签 统计

php ×2

aes ×1

c# ×1

c++ ×1

encryption ×1

md5 ×1