สำหรับตัวอย่างการเข้ารหัสและถอดรหัสเป็นดังนี้
use phpseclib\Crypt\RSA; ... $publicKey = 'MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQCEa1ivzN/iW1wBTyT1T6uPcDKzi3HlCBCp3ro61ZxA1byilNH/TP7HW3iFAh0A0Lyk7dZ7d6Ot4jdsXc783T+Ic0n2Blfh0kCm0ci7q2qXqOLpCa6N30LQyiDofSmaLRzQlD49kjVY8GJYrdqo7lEQvBupenJzjS71LgkIqq+BeQIDAQAB'; $privateKey = 'MIICXQIBAAKBgQCEa1ivzN/iW1wBTyT1T6uPcDKzi3HlCBCp3ro61ZxA1byilNH/TP7HW3iFAh0A0Lyk7dZ7d6Ot4jdsXc783T+Ic0n2Blfh0kCm0ci7q2qXqOLpCa6N30LQyiDofSmaLRzQlD49kjVY8GJYrdqo7lEQvBupenJzjS71LgkIqq+BeQIDAQABAoGAVfYZrIYjEJ6eK3tlUppVlNgREd0EItoJdzzPSEJDHROjUSeq60DgZCpNIossqMrYq3h6M8yGxOqFcCO1qxE1nDhwMRxNYALnM8yBfVTe/RfASD7A+XLBB4HKOPPAs7HjPj6rdJpTSLxSNFXW7lMmw+AUTuI1B5TTqINWR83rewECQQDrYAXjdB9/Xg2x+tW6kBh3Dcdm12d3bTIXklfVeds4/3tvJyZkWi/FnNAkZLG40+R39xzP2s+XbN4Ul14aok4VAkEAkAXNBC++X+91esEIwTf4RTMxn7Q/m5F9j7G827bTWUJ+oPCoCnmdLth+9QfMyVboo4D7P8w+trm665+emV7i1QJBALdBZrRFh/RxdPY6VkdPw0yGFNb0JKFuCg8iKHKT0mPZPfA3qgN92C3iPofnQhumFf51DiCiuvepkmqzw1e3QFUCQEDznMYqkfzKDX1S2RPqnfj3YYXY0Gbkcm//hGDCTwaOSnVikyZGOnEKChePcPfMThaO8MCQ6CeYE4h38BrTBBECQQDDp8w+aItksMhcLGIyPRZZmlLew6ic+Pv+8fES9apzy/13MbBpxm/oPVavftLQi+6N29eTtqbE7lL1hRcdsUqn'; $plaintext = 'test'; $rsa = new RSA(); $rsa->loadKey($publicKey); $ciphertext = $rsa->encrypt($plaintext); $rsa->loadKey($privateKey); echo $rsa->decrypt($ciphertext);สำหรับตัวอย่างการ Verify key เป็นดังนี้
$plaintext = 'ThisIsTest'; $rsa = new RSA(); $rsa->loadKey($privateKey); $signature = $rsa->sign($plaintext); $rsa->loadKey($publicKey); $rsa->verify($plaintext, $signature); // Throw exception if verification is failed
No comments:
Post a Comment