本文整理汇总了PHP中Crypt_RSA::encrypt方法的典型用法代码示例。如果您正苦于以下问题:PHP Crypt_RSA::encrypt方法的具体用法?PHP Crypt_RSA::encrypt怎么用?PHP Crypt_RSA::encrypt使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Crypt_RSA
的用法示例。
在下文中一共展示了Crypt_RSA::encrypt方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: asymmetricEncrypt
/**
* Encrypts data using RSA
* @param String $data Data to encrypt
* @return String
*/
public function asymmetricEncrypt($data)
{
if (!$this->isRsaInitialized) {
$this->initAsymmetric();
}
return Base64::UrlEncode($this->rsa->encrypt($data));
}
示例2: RSA_Encrypt
function RSA_Encrypt($plaintext, $publicKey)
{
$rsa = new Crypt_RSA();
$rsa->loadKey($publicKey);
$rsa->setEncryptionMode(CRYPT_RSA_ENCRYPTION_PKCS1);
return base64_encode($rsa->encrypt($plaintext));
}
示例3: encrypt_message
function encrypt_message($plaintext, $asym_key, $key_length = 150)
{
$rsa = new Crypt_RSA();
$rij = new Crypt_Rijndael();
// Generate Random Symmetric Key
$sym_key = crypt_random_string($key_length);
// Encrypt Message with new Symmetric Key
$rij->setKey($sym_key);
$ciphertext = $rij->encrypt($plaintext);
$ciphertext = base64_encode($ciphertext);
// Encrypted the Symmetric Key with the Asymmetric Key
$rsa->loadKey($asym_key);
$sym_key = $rsa->encrypt($sym_key);
// Base 64 encode the symmetric key for transport
$sym_key = base64_encode($sym_key);
$len = strlen($sym_key);
// Get the length
$len = dechex($len);
// The first 3 bytes of the message are the key length
$len = str_pad($len, 3, '0', STR_PAD_LEFT);
// Zero pad to be sure.
// Concatinate the length, the encrypted symmetric key, and the message
$message = $len . $sym_key . $ciphertext;
return $message;
}
示例4: testSuppliedKey
public function testSuppliedKey()
{
// $ openssl genrsa -out key.pem 512
$generatedKey = <<<EOL
-----BEGIN RSA PRIVATE KEY-----
MIIBOwIBAAJBAKihibtt92M6A/z49CqNcWugBd3sPrW3HF8TtKANZd1EWQ/agZ65
H2/NdL8H6zCgmKpYFTqFGwlYrnWrsbD1UxcCAwEAAQJAWX5pl1Q0D7Axf6csBg1M
3V5u3qlLWqsUXo0ZtjuGDRgk5FsJOA9bkxfpJspbr2CFkodpBuBCBYpOTQhLUc2H
MQIhAN1stwI2BIiSBNbDx2YiW5IVTEh/gTEXxOCazRDNWPQJAiEAwvZvqIQLexer
TnKj7q+Zcv4G2XgbkhtaLH/ELiA/Fh8CIQDGIC3M86qwzP85cCrub5XCK/567GQc
GmmWk80j2KpciQIhAI/ybFa7x85Gl5EAS9F7jYy9ykjeyVyDHX0liK+V1355AiAG
jU6zr1wG9awuXj8j5x37eFXnfD/p92GpteyHuIDpog==
-----END RSA PRIVATE KEY-----
EOL;
// $ openssl rsa -pubout -in key.pem
$publickey = <<<EOL
-----BEGIN PUBLIC KEY-----
MFwwDQYJKoZIhvcNAQEBBQADSwAwSAJBAKihibtt92M6A/z49CqNcWugBd3sPrW3
HF8TtKANZd1EWQ/agZ65H2/NdL8H6zCgmKpYFTqFGwlYrnWrsbD1UxcCAwEAAQ==
-----END PUBLIC KEY-----
EOL;
$rsa = new Crypt_RSA();
$rsa->loadKey($publickey);
$str = "123";
$enc = $rsa->encrypt($str);
// echo "encoded=",bin2hex($enc),"\n";
$rsa->loadKey($generatedKey);
$dec = $rsa->decrypt($enc);
$this->assertEquals($str, $dec, "Basic Encrypt/Decrypt with Supplied key.");
}
示例5: encryptChallenge
function encryptChallenge($publicKey, $rnd)
{
$rsa = new Crypt_RSA();
$rsa->loadKey($publicKey);
$rsa->setEncryptionMode(CRYPT_RSA_ENCRYPTION_PKCS1);
$ciphertext = $rsa->encrypt($rnd);
return base64_encode($ciphertext);
}
示例6: getEncryptedPassword
private function getEncryptedPassword()
{
$key = $this->getRSAKey();
$rsa = new Crypt_RSA();
$rsa->setEncryptionMode(CRYPT_RSA_ENCRYPTION_PKCS1);
$rsa->loadKey(['n' => new Math_BigInteger($key->publickey_mod, 16), 'e' => new Math_BigInteger($key->publickey_exp, 16)]);
return ['code' => base64_encode($rsa->encrypt($this->pass)), 'time' => $key->timestamp];
}
示例7: criptografar
function criptografar($texto)
{
$rsa = new Crypt_RSA();
$rsa->setEncryptionMode(CRYPT_RSA_ENCRYPTION_PKCS1);
$rsa->setSignatureMode(CRYPT_RSA_SIGNATURE_PKCS1);
$rsa->loadKey($_SESSION['chave_publica']);
return base64_encode($rsa->encrypt($texto));
}
示例8: RSAEncrypt
function RSAEncrypt($text, $pem)
{
$x509 = new File_X509();
$rsa = new Crypt_RSA();
$x509->loadX509($pem);
$rsa->loadKey($x509->getPublicKey());
$rsa->setEncryptionMode(CRYPT_RSA_ENCRYPTION_PKCS1);
return bin2hex($rsa->encrypt($text));
}
示例9: encrypt
function encrypt($data = "")
{
$keys = $this->getKeys();
$path = get_include_path();
$rsa = new Crypt_RSA();
$rsa->loadKey($keys->publickey);
set_include_path($path);
return $rsa->encrypt($data);
}
示例10: isValidKey
/**
* Return true if $pub_k and $pri_k encode and decode the same text
*
* @param String $pub_k
* @param String $pri_k
* @return boolean
*/
static function isValidKey($pub_k, $pri_k)
{
$plaintext = 'pippopippo';
$rsa = new Crypt_RSA();
$rsa->loadKey($pub_k);
$ciphertext = $rsa->encrypt($plaintext);
$rsa->loadKey($pri_k);
return $plaintext == $rsa->decrypt($ciphertext);
}
示例11: index
/**
* Index action
*/
function index()
{
$rsa = new Crypt_RSA();
$rsa->loadKey(ConfigOptions::getValue('frosso_auth_my_pub_key'));
$text = 'frosso@remedia.it;' . ConfigOptions::getValue('frosso_auth_my_pri_token', false) . ';' . time();
$crypt = $rsa->encrypt($text);
echo '<textarea cols="200">' . $crypt . "</textarea>";
echo '<br/><textarea cols="200">' . urlencode($crypt) . "</textarea>";
$this->response->badRequest();
}
示例12: encrypt
function encrypt($data = "")
{
$keys = $this->getKeys();
$path = get_include_path();
set_include_path("lib/phpseclib/");
require_once 'Crypt/RSA.php';
$rsa = new Crypt_RSA();
$rsa->loadKey($keys->privatekey);
set_include_path($path);
return $rsa->encrypt($data);
}
示例13: rsa_encrypt
public function rsa_encrypt($plain_text, $publicKey)
{
$oldIncludePath = get_include_path();
$include = realpath(dirname(__FILE__));
set_include_path($include . DIRECTORY_SEPARATOR . 'CryptLib');
include_once 'Crypt/RSA.php';
$rsa = new Crypt_RSA();
$rsa->loadKey($publicKey);
$ciphertext = $rsa->encrypt($plain_text);
set_include_path($oldIncludePath);
return base64_encode($ciphertext);
}
示例14: verify
/**
* Attempts to use the key with current passkey thus making sure that
* passphrase works
*/
function verify()
{
$rsa = new Crypt_RSA();
$rsa->loadKey($this['notes']);
$encrypt = $rsa->encrypt('test');
$pack = $this->app->getPackingKey();
if ($pack) {
$rsa->setPassword($pack);
}
$rsa->loadKey($this['data']);
$text = $rsa->decrypt($encrypt);
// Missmatch here shouldn't happen. It would rather throw
// exception during decrypt();
return $text == 'test' ? 'Successful' : 'Descryption missmatch';
}
示例15: publicEncrypt
public function publicEncrypt($data, $publicKey)
{
$this->requireLibrary();
$rsa = new Crypt_RSA();
$rsa->setEncryptionMode(CRYPT_RSA_SIGNATURE_PKCS1);
$rsa->loadKey($publicKey, CRYPT_RSA_PUBLIC_FORMAT_PKCS1);
$errorCatcher = new MWP_Debug_ErrorCatcher();
$errorCatcher->register();
$encrypted = $rsa->encrypt($data);
$error = $errorCatcher->yieldErrorMessage(true);
if ($encrypted === false && $error !== null) {
throw new MWP_Worker_Exception(MWP_Worker_Exception::PHPSECLIB_ENCRYPT_ERROR, "Error while trying to use OpenSSL to encrypt a message.", array('error' => $error));
}
return $encrypted;
}