회원로그인

회원가입 정보찾기
포인트로 가상매매하실 수 있습니다.
코인 현재가 전일비 매매하기
BTC 85,488,000 ▼ 116,000 매매하기
ETH 4,767,000 ▼ 31,000 매매하기
ETC 33,350 ▼ 170 매매하기
XRP 668 ▼ 5 매매하기
BCH 539,500 ▼ 15,000 매매하기
QTUM 3,645 ▼ 58 매매하기
BTG 35,000 ▼ 380 매매하기
EOS 825 ▼ 10 매매하기
PHP

rsa 암호화 클래스

페이지 정보

  • 작성자 최고관리자
  • 작성일 18-09-20 09:33
  • 조회 2,676회
  • 댓글 0건

본문

<?php
// http://php.net/manual/en/function.openssl-pkey-new.php
class TBRsa {
 public $privateKey, $publicKey;
 public function __construct($pubKey=, $privKey=) {


  if($pubKey) $this->publicKey = $pubKey;
  if($privKey) $this->privateKey = $privKey;
 }
 public function MakeKey() {
  $res = openssl_pkey_new(array(
   "digest_alg" => "sha256",
   "private_key_bits" => 2048,
   "private_key_type" => OPENSSL_KEYTYPE_RSA
  ));
  openssl_pkey_export($res, $privKey);
  $this->privateKey = $privKey;


  $pubKey = openssl_pkey_get_details($res);
  $this->publicKey = $pubKey[key];
 }
 public function ViewKey() {
  return array(publicKey=>$this->publicKey, privateKey=>$this->privateKey);
 }
 public function Encrypt($data) {
  $pubKey = $this->publicKey;
  if(!$pubKey) die(공개키를 입력하세요.);
  openssl_public_encrypt($data, $encrypted, $pubKey);
  return base64_encode($encrypted);
 }
 public function Decrypt($data) {
  $privKey = $this->privateKey;
  if(!$privKey) die(개인키를 입력하세요.);
  $data = base64_decode($data);
  openssl_private_decrypt($data, $decrypted, $privKey);
  return $decrypted;
 }
}




$pb = -----BEGIN PUBLIC KEY-----
MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAx0sWpnpwQ6tGZV0KGgpu
xTZXpretvCxuBWTxzZbC2hi86fz05f9PDtQHagHnn1bywNIieMOzbZ78Z/o178GV
dAVz3nZyC2LxRxDd1ylZLJz0HWiUxR0t35S04Smr83KBFS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SEdJ/hOwq6qUuuqkZ
1ZtkYjoTenpBTpZ0uNWgjJIc80joaVkLaOY1mCdLye6AbyzbpJAsd6TlscFxWHVA
/Tt+6zIf0YE2fCgq0mL2wf7uZ1MCgYEA1IPQMWeztDljbUKSxHSeOGE5IS6c1uZH
EOndbeYyPmJHRTdu721KAAYYv0JQHZsTCIWof5hIj9JSFrycgRZkZ6SaI8vINX33
f42R22KICcQ+gE03xTUIGgQJxOw6PXtmndnwBX544UMXDqnvZcRNN1VhbV2K/7rT
AOnZpXrAY6MCgYEAvPqpAmPIz+C37Y2L9Wk0yUqwHou1GlyBBcyNZtbFrfpfUG/i
hbD1VjvI3zPuxlXYiYj+8p6Jxf3ThAI7IOfapGv9C0uTfw52wU0AvccC3QvGT69V
iPS2uZgtU77YASv5llgbeO8oFL4mwDBEwVKFPRVO8LdbMW7ZDpXykpFgD5sCgYAq
yyRIXpaMSyYfYVGGp+kYd1N2wBkrGRHkcQN61uj1MPsjEAeRxRMqsA+Zq/PQEmMh
yzBkCTlLZNHM7Ewjnmu3hyjW3nlBdE07bTma0NuOA+uGEIaTeptYCcoh0mPj7455
aOJxaMdUrRrehA/GEWJvKw1EZZrQ5kEJJQ4DyZUmOwKBgH7+lhffVhG67oPcqKAs
JdjP3rCDGckoZO6g7lONWiKzlgZHX8hb2SJjys6vW0+tE/1M3rdHG/Q/y5rV/IaK
vvIgKJy74uj6AJtbystK/1uqLmuVEYgN+5NJj9J2hSf30flel1xVOYxMQnjJ6LI7
cMxleiKYRi/4rc5OwKe3eVrK
-----END PRIVATE KEY-----; // 개인키



$TE = new TBRsa($pb, $pv);
$en = $TE->Encrypt(와웅);
$dn = $TE->Decrypt($en);
echo $en.<hr>;
echo $dn;




포인트 선물 선물명단 선물하기

최소 50P ~ 최대 300P 까지 가능합니다.
선물하기 수수료는 10P 입니다.
로그인 후 선물하실 수 있습니다.

선물 받은 내용이 없습니다.

댓글목록

등록된 댓글이 없습니다.