本文整理汇总了PHP中Crypt_AES类的典型用法代码示例。如果您正苦于以下问题:PHP Crypt_AES类的具体用法?PHP Crypt_AES怎么用?PHP Crypt_AES使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Crypt_AES类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: AESDecrypt
function AESDecrypt($ciphertext, $key, $IV)
{
$aes = new Crypt_AES(CRYPT_MODE_ECB);
$aes->setKey(characet($key));
$aes->setIV(characet($IV));
return $aes->decrypt(hex2bin($ciphertext));
}
示例2: cipher
private function cipher()
{
switch ($this->header['enc']) {
case 'A128GCM':
case 'A256GCM':
throw new JOSE_Exception_UnexpectedAlgorithm('Algorithm not supported');
case 'A128CBC-HS256':
case 'A256CBC-HS512':
$cipher = new Crypt_AES(CRYPT_AES_MODE_CBC);
break;
default:
throw new JOSE_Exception_UnexpectedAlgorithm('Unknown algorithm');
}
switch ($this->header['enc']) {
case 'A128GCM':
case 'A128CBC-HS256':
$cipher->setBlockLength(128);
break;
case 'A256GCM':
case 'A256CBC-HS512':
$cipher->setBlockLength(256);
break;
default:
throw new JOSE_Exception_UnexpectedAlgorithm('Unknown algorithm');
}
return $cipher;
}
示例3: _pugpig_bbappworld_decrypt
function _pugpig_bbappworld_decrypt($base64_encrypted, $password)
{
$cipher = new Crypt_AES(CRYPT_AES_MODE_ECB);
// keys are null-padded to the closest valid size
// longer than the longest key and it's truncated
$cipher->setKey($password);
return $cipher->decrypt(base64_decode($base64_encrypted));
}
示例4: decodeResponse
protected function decodeResponse($received)
{
$aes = new Crypt_AES();
$aes->setKey($this->key);
$data = $aes->decrypt(base64_decode(substr($received, 28)));
$decoder = new XmlrpcDecoder();
return $decoder->decodeResponse($data);
}
示例5: getApi
/**
* Returns an instance of the Crypto library
* @return Crypt_AES
*/
public function getApi()
{
if (is_null($this->api)) {
$this->api = new AES();
$this->api->setKey($this->getKey());
}
return $this->api;
}
示例6: decryptAES
/**
* Decrypt the provided data using AES cryptography with the provided key and IV
*
* @param string $data Data to decrypt
* @param string $key Cipher key used to encrypt the data
* @param string $iv IV used to encrypt the data
* @param bool $base64Encoded Is the provided data Base64 encoded (defaults to true)
* @return string Unencrypted data
*/
public function decryptAES($data, $key, $iv, $base64Encoded = true)
{
$data = $base64Encoded ? base64_decode($data) : $data;
$cipher = new \Crypt_AES();
$cipher->setKey($key);
$cipher->setIV($iv);
$cipher->disablePadding();
$decrypted = rtrim($cipher->decrypt($data));
return $decrypted;
}
示例7: testKeyPaddingAES
/**
* @group github451
*/
public function testKeyPaddingAES()
{
// same as the above - just with a different ciphertext
$aes = new Crypt_AES();
$aes->disablePadding();
$aes->setKey(pack('H*', '2b7e151628aed2a6abf7158809cf4f3c762e7160'));
// 160-bit key. AES should null pad to 192-bits
$ciphertext = $aes->encrypt(pack('H*', '3243f6a8885a308d313198a2e0370734'));
$this->assertEquals($ciphertext, pack('H*', 'c109292b173f841b88e0ee49f13db8c0'));
}
示例8: create_message
public function create_message(model\api_message $message)
{
$payload = serialize($message);
$key = $this->key;
$salt = crypt(microtime() . mt_rand(0, mt_getrandmax()));
$cipher = new \Crypt_AES(CRYPT_AES_MODE_ECB);
$cipher->setPassword($key, 'pbkdf2', 'sha256', $salt, 1000);
$payload_enc = $cipher->encrypt($payload);
$message = base64_encode(serialize(array('s' => $salt, 'p' => $payload_enc, 't' => @gmmktime())));
return $message;
}
示例9: decrypt
public static function decrypt($secret, $password, ApiKeyEncryptionOptions $options)
{
$decodedSecret = self::base64url_decode($secret);
$salt = self::base64url_decode($options->getEncryptionKeySalt());
$iterations = $options->getEncryptionKeyIterations();
$keyLengthBits = $options->getEncryptionKeySize();
$iv = substr($decodedSecret, 0, 16);
$aes = new \Crypt_AES();
$aes->setPassword($password, 'pbkdf2', 'sha1', $salt, $iterations, $keyLengthBits / 8);
$aes->setKeyLength($keyLengthBits);
$aes->setIV($iv);
return $aes->decrypt(substr($decodedSecret, 16));
}
示例10: loginWSAuthenticate
/**
* Checks whether a user has the right to enter on the platform or not
* @param string The username, as provided in form
* @param string The cleartext password, as provided in form
* @param string The WS URL, as provided at the beginning of this script
*/
function loginWSAuthenticate($username, $password, $wsUrl)
{
// check params
if (empty($username) or empty($password) or empty($wsUrl)) {
return false;
}
// Create new SOAP client instance
$client = new SoapClient($wsUrl);
if (!$client) {
return false;
}
// Include phpseclib methods, because of a bug with AES/CFB in mcrypt
include_once api_get_path(LIBRARY_PATH) . 'phpseclib/Crypt/AES.php';
// Define all elements necessary to the encryption
$key = '-+*%$({[]})$%*+-';
// Complete password con PKCS7-specific padding
$blockSize = 16;
$padding = $blockSize - strlen($password) % $blockSize;
$password .= str_repeat(chr($padding), $padding);
$cipher = new Crypt_AES(CRYPT_AES_MODE_CFB);
$cipher->setKeyLength(128);
$cipher->setKey($key);
$cipher->setIV($key);
$cipheredPass = $cipher->encrypt($password);
// Mcrypt call left for documentation purposes - broken, see https://bugs.php.net/bug.php?id=51146
//$cipheredPass = mcrypt_encrypt(MCRYPT_RIJNDAEL_128, $key, $password, MCRYPT_MODE_CFB, $key);
// Following lines present for debug purposes only
/*
$arr = preg_split('//', $cipheredPass, -1, PREG_SPLIT_NO_EMPTY);
foreach ($arr as $char) {
error_log(ord($char));
}
*/
// Change to base64 to avoid communication alteration
$passCrypted = base64_encode($cipheredPass);
// The call to the webservice will change depending on your definition
try {
$response = $client->validateUser(array('user' => $username, 'pass' => $passCrypted, 'system' => 'chamilo'));
} catch (SoapFault $fault) {
error_log('Caught something');
if ($fault->faultstring != 'Could not connect to host') {
error_log('Not a connection problem');
throw $fault;
} else {
error_log('Could not connect to WS host');
}
return 0;
}
return $response->validateUserResult;
}
示例11: fileRead
function fileRead($key)
{
$file = fopen("data.php", "r");
$aes = new Crypt_AES();
$aes->setKey($key);
$tempdata = "";
if ($file) {
$tempdata = file_get_contents("data.php");
$tempdata = substr($tempdata, strlen($GLOBALS["fileStart"]));
$tempdata = $aes->decrypt(substr($tempdata, 0, -strlen($GLOBALS["fileEnd"])));
}
fclose($file);
return $tempdata;
}
示例12: initAes
protected function initAes($key, $iv, $keySize)
{
$this->aes = new \Crypt_AES();
$this->aes->setKeyLength($keySize);
$this->aesKey = $key;
$this->aesIV = $iv;
$this->aes->setKey($this->aesKey);
$this->aes->setIV($this->aesIV);
}
示例13: pac_message_receiver
public function pac_message_receiver()
{
$content = Req::post("content");
if (!isset($content)) {
$this->returnXML("false", "S09", "返回报文为空");
}
$signature = Req::post("data_digest");
if (!isset($signature)) {
$this->returnXML("false", "S09", "返回报文为空");
}
Tiny::log("异步审批结果回执信息【content:" . $content . "】data_digest【" . $signature . "】");
// 测试密钥
$aeskey = base64_decode($this->jkf['aes_key']);
//AES解密,采用ECB模式
$aes = new Crypt_AES(CRYPT_MODE_ECB);
//设置AES密钥
$aes->setKey($aeskey);
//解密AES密文
$plaintext = $aes->decrypt(base64_decode($content));
//测试rsa公钥
$publickey = $this->jkf['public_key'];
$rsa = new Crypt_RSA();
//设置RSA签名模式 CRYPT_RSA_SIGNATURE_PSS or CRYPT_RSA_SIGNATURE_PKCS1
$rsa->setSignatureMode(CRYPT_RSA_SIGNATURE_PKCS1);
//使用RSA公钥验证签名
$rsa->loadKey(base64_decode($publickey));
//签名通过
if ($rsa->verify($plaintext, base64_decode($signature))) {
$contentXML = simplexml_load_string($plaintext);
$businessType = (string) $contentXML->head->businessType;
$model = new GatewayModel();
if ($businessType == "RESULT") {
$model->insertResult($contentXML, "1");
} else {
if ($businessType == "PRODUCT_RECORD") {
$model->insertExamineResult($contentXML);
}
}
$this->returnXML();
} else {
$this->returnXML("false", "S02", "非法的数字签名");
}
}
示例14: attendance
function attendance()
{
require_once 'AES.php';
$aes = new Crypt_AES();
$aes->setKey($this->site->conf['AESKey']);
switch ($_GET['page'] ? $_GET['page'] : 00) {
case 00:
if ($this->site->userPermit == '3') {
$auth = base64_encode($aes->encrypt($_COOKIE['email'] . ' ' . $_COOKIE['pass']));
setcookie('email', $_POST['email'], 0, '/');
setcookie('pass', md5($_POST['password']), 0, '/');
$team = $this->mysql->get_rows('SELECT * FROM `team` WHERE `active` = YEAR(CURDATE()) ORDER BY `name` ASC ');
foreach ($team as $key => $i) {
$list[] = array('<% ID %>' => $i['id'], '<% NAME %>' => $i['name']);
}
$ret = $this->templates->process_between('attendance.html', '<% STUDENTS %>', $list);
$ret = $this->templates->process($ret, array('<% AUTH %>' => $auth));
echo $this->templates->template('Team Attendance', array(), $ret);
} else {
$this->site->home_page();
}
break;
case 01:
list($email, $pass) = explode(' ', $aes->decrypt(base64_decode($_POST['auth'])));
if ($this->site->checkCredentials($email, $pass) && $this->site->userPermit == '3') {
die("1");
} else {
die("0");
}
break;
case 02:
$pass = $this->mysql->get_row('SELECT `password` FROM `team` WHERE `id` = ' . $_POST['id'] . ' LIMIT 1');
if ($pass['password'] == md5($_POST['pass'])) {
$this->mysql->query("INSERT INTO `attendence` (`id`, `date`, `teamid`) VALUES (NULL, CURDATE(), '" . $_POST['id'] . "')");
die("1");
}
break;
}
}
示例15: decrypt_data
public function decrypt_data($input_str, $key = SEC_STR)
{
$aes = new Crypt_AES();
$aes->setKey($key);
return $aes->decrypt($input_str);
}