本文整理汇总了PHP中Crypt_AES::encrypt方法的典型用法代码示例。如果您正苦于以下问题:PHP Crypt_AES::encrypt方法的具体用法?PHP Crypt_AES::encrypt怎么用?PHP Crypt_AES::encrypt使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Crypt_AES
的用法示例。
在下文中一共展示了Crypt_AES::encrypt方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: symmetricEncrypt
/**
* Encrypts data using AES
* @param String $data Data to encrypt
* @return String
*/
public function symmetricEncrypt($data)
{
if (!$this->isAesInitialized) {
$this->initSymmetric();
}
return $this->aes->encrypt($data);
}
示例2: AESEncrypt
function AESEncrypt($text, $key, $IV)
{
$aes = new Crypt_AES(CRYPT_MODE_ECB);
$aes->setKey(characet($key));
$aes->setIV(characet($IV));
return bin2hex($aes->encrypt($text));
}
示例3: encodeRequest
protected function encodeRequest($method, $parameters)
{
$encoder = new XmlrpcEncoder();
$data = $encoder->encodeCall($method, $parameters);
$aes = new Crypt_AES();
$aes->setKey($this->key);
return 'comodojo_encrypted_request-' . base64_encode($aes->encrypt($data));
}
示例4: pre_update_option_filter
/**
* Process the launchkey option to prepare for storage in the database. The method will encrypt the data and set
* the current version so that the option may be programmatically updated in place in the future.
*
* @since 1.0.0
*
* @param array $input
*
* @return array
*/
public function pre_update_option_filter(array $input)
{
$output = $input;
$output['version'] = static::VERSION;
if (!empty($input[LaunchKey_WP_Options::OPTION_SECRET_KEY])) {
$key = md5($input[LaunchKey_WP_Options::OPTION_SECRET_KEY]);
if (empty($this->cache[$key])) {
/**
* Use the rocket key as the IV. If null, use the static value.
* @link https://docs.launchkey.com/glossary.html#term-iv
*/
$iv = empty($input[LaunchKey_WP_Options::OPTION_ROCKET_KEY]) ? static::STATIC_IV : $input[LaunchKey_WP_Options::OPTION_ROCKET_KEY];
$this->crypt_aes->setIV($iv);
/**
* Encrypt and Base64 encode the encrypted value and set it as the output value
* @link https://docs.launchkey.com/glossary.html#term-base64
*/
$this->cache[$key] = base64_encode($this->crypt_aes->encrypt($input[LaunchKey_WP_Options::OPTION_SECRET_KEY]));
}
$output[LaunchKey_WP_Options::OPTION_SECRET_KEY] = $this->cache[$key];
} else {
$output[LaunchKey_WP_Options::OPTION_SECRET_KEY] = null;
}
if (!empty($input[LaunchKey_WP_Options::OPTION_PRIVATE_KEY])) {
$key = md5($input[LaunchKey_WP_Options::OPTION_PRIVATE_KEY]);
if (empty($this->cache[$key])) {
/**
* Use the decrypted secret key as the IV. If null, use the static value.
* @link https://docs.launchkey.com/glossary.html#term-iv
*/
$iv = empty($input[LaunchKey_WP_Options::OPTION_SECRET_KEY]) ? static::STATIC_IV : $input[LaunchKey_WP_Options::OPTION_SECRET_KEY];
$this->crypt_aes->setIV($iv);
/**
* Encrypt and Base64 encode the encrypted value and set it as the output value
* @link https://docs.launchkey.com/glossary.html#term-base64
*/
$this->cache[$key] = base64_encode($this->crypt_aes->encrypt($input[LaunchKey_WP_Options::OPTION_PRIVATE_KEY]));
}
$output[LaunchKey_WP_Options::OPTION_PRIVATE_KEY] = $this->cache[$key];
} else {
$output[LaunchKey_WP_Options::OPTION_PRIVATE_KEY] = null;
}
return $output;
}
示例5: _pugpig_bbappworld_encrypt
function _pugpig_bbappworld_encrypt($plaintext, $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);
$encrypted = $cipher->encrypt($plaintext);
$base64_encrypted = base64_encode($encrypted);
return $base64_encrypted;
}
示例6: 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'));
}
示例7: fileWrite
function fileWrite($data, $key)
{
$file = fopen("data.php", "w+");
$aes = new Crypt_AES();
$aes->setKey($key);
if ($file) {
fwrite($file, $GLOBALS["fileStart"] . $aes->encrypt($data) . $GLOBALS["fileEnd"]);
}
fclose($file);
}
示例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: 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;
}
示例10: encryptThenSign
/**
* Encrypt $plaintext with $secret, then date and sign the message.
*
* @param string $secret
* @param string $plaintext
* @return array
* Array(string $body, string $signature).
* Note that $body begins with an unencrypted envelope (ttl, iv).
* @throws InvalidMessageException
*/
public static function encryptThenSign($secret, $plaintext)
{
$iv = crypt_random_string(Constants::AES_BYTES);
$keys = AesHelper::deriveAesKeys($secret);
$cipher = new \Crypt_AES(CRYPT_AES_MODE_CBC);
$cipher->setKeyLength(Constants::AES_BYTES);
$cipher->setKey($keys['enc']);
$cipher->setIV($iv);
// JSON string; this will be signed but not encrypted
$jsonEnvelope = json_encode(array('ttl' => Time::getTime() + Constants::REQUEST_TTL, 'iv' => BinHex::bin2hex($iv)));
// JSON string; this will be signed and encrypted
$jsonEncrypted = $cipher->encrypt($plaintext);
$body = $jsonEnvelope . Constants::PROTOCOL_DELIM . $jsonEncrypted;
$signature = hash_hmac('sha256', $body, $keys['auth']);
return array($body, $signature);
}
示例11: encrypt_data
public function encrypt_data($input_str, $key = SEC_STR)
{
$aes = new Crypt_AES();
$aes->setKey($key);
return $aes->encrypt($input_str);
}
示例12: fopen
if (is_writable("../.ssh/passphrase")) {
$handle = fopen('../.ssh/passphrase', 'w');
fwrite($handle, $newPassphrase);
fclose($handle);
}
//---------------------------------------------------------+
require_once "../libs/phpseclib/Crypt/AES.php";
$aes = new Crypt_AES();
$aes->setKeyLength(256);
//---------------------------------------------------------+
$boxes = mysql_query("SELECT `boxid`, `password` FROM `" . DBPREFIX . "box`");
while ($rowsBoxes = mysql_fetch_assoc($boxes)) {
$aes->setKey($oldPassphrase);
$password = $aes->decrypt($rowsBoxes['password']);
$aes->setKey($newPassphrase);
$password = $aes->encrypt($password);
query_basic("UPDATE `" . DBPREFIX . "box` SET `password` = '" . mysql_real_escape_string($password) . "' WHERE `boxid` = '" . $rowsBoxes['boxid'] . "'");
unset($password);
}
unset($boxes);
}
unset($line);
//---------------------------------------------------------+
//Updating structure for table "log"
query_basic("ALTER TABLE `" . DBPREFIX . "log` ADD `scriptid` int(8) UNSIGNED NULL");
//---------------------------------------------------------+
//Updating structure for table "script"
query_basic("ALTER TABLE `" . DBPREFIX . "script` CHANGE `daemon` `type` int(1) NOT NULL ");
//Updating data for table "config"
query_basic("UPDATE `" . DBPREFIX . "config` SET `value` = '0.3.5' WHERE `setting` = 'panelversion' LIMIT 1");
query_basic("\n\t\tINSERT INTO `" . DBPREFIX . "config` (`setting`, `value`)\n\t\tVALUES\n\t\t ('maintenance', '0') ; ");
示例13: auth_encrypt
/**
* Encrypt data using the given secret using AES
*
* The mode is CBC with a random initialization vector, the key is derived
* using pbkdf2.
*
* @param string $data The data that shall be encrypted
* @param string $secret The secret/password that shall be used
* @return string The ciphertext
*/
function auth_encrypt($data, $secret)
{
$iv = auth_randombytes(16);
$cipher = new Crypt_AES();
$cipher->setPassword($secret);
/*
this uses the encrypted IV as IV as suggested in
http://csrc.nist.gov/publications/nistpubs/800-38a/sp800-38a.pdf, Appendix C
for unique but necessarily random IVs. The resulting ciphertext is
compatible to ciphertext that was created using a "normal" IV.
*/
return $cipher->encrypt($iv . $data);
}
示例14: encryptData
function encryptData($data)
{
global $cryptkey;
if (!$data) {
return false;
}
$aes = new Crypt_AES();
$aes->setKey($cryptkey);
$cryptdata = $aes->encrypt($data);
return trim(base64_encode($cryptdata));
}
示例15: cookieEncrypt
/**
* Encryption using openssl's AES or phpseclib's AES
* (phpseclib uses mcrypt when it is available)
*
* @param string $data original data
* @param string $secret the secret
*
* @return string the encrypted result
*/
public function cookieEncrypt($data, $secret)
{
if ($this->_useOpenSSL()) {
return openssl_encrypt($data, 'AES-128-CBC', $secret, 0, $this->_cookie_iv);
} else {
$cipher = new Crypt_AES(CRYPT_AES_MODE_CBC);
$cipher->setIV($this->_cookie_iv);
$cipher->setKey($secret);
return base64_encode($cipher->encrypt($data));
}
}