<?php
/**
* App RSA 加密解密辅助函数
**/
function app_pri_encrypt($data){$privateKey = openssl_pkey_get_private(file_get_contents("app-private.key"));
$encrypted = null;
openssl_private_encrypt($data,$encrypted,$privateKey);
return base64_encode($encrypted);
}
function app_pri_decrypt($data){$privateKey = openssl_pkey_get_private(file_get_contents("app-private.key"));
$decrypted = null;
openssl_private_decrypt(base64_decode($data),$decrypted,$privateKey);
return $decrypted;
}
function app_pub_encrypt($data){$publicKey = openssl_pkey_get_public(file_get_contents("app-public.key"));
$encrypted = null;
openssl_public_encrypt($data,$encrypted,$publicKey);
return base64_encode($encrypted);
}
function app_pub_decrypt($data){$publicKey = openssl_pkey_get_public(file_get_contents("app-public.key"));
$decrypted = null;
openssl_public_decrypt(base64_decode($data),$decrypted,$publicKey);
return $decrypted;
}