使用我自己的密钥文件进行RSP加密 [英] RSP encryption with my own key file
本文介绍了使用我自己的密钥文件进行RSP加密的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
好,所以我是密码学的新手
Ok so i am VERY new to cryptography
我想使用RSA加密字符串.我发现了很多示例,但大多数示例都会生成自己的公钥/私钥,或者使用其他一些密钥格式,例如pem/crt等
I want to encrypt a string using RSA. i have found many examples but most of them generate their own public/private keys or they use some other key format like pem/crt etc
我有自己的.key格式的公钥和私钥文件
I have my own public and private key file in the format of .key
Public key -> http://pastebin.com/hPT9LRCT
Private key-> http://pastebin.com/UYgJp8K7
如何使用php中的公共密钥加密字符串("hello world")?
How do i encrypt a string ("hello world") using my public key in php?
您能给我看看一个例子还是指向正确的方向吗?
Could you show me an example or point me in the right direction?
谢谢,Vidhu
推荐答案
尝试一下(使用 phpseclib,纯PHP RSA实现):
<?php
include('Crypt/RSA.php');
$rsa = new Crypt_RSA();
$rsa->loadKey('MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEArd+uKDi7g6cpmbotPre9KpFK4U1rM/FlEtHszIrMBmArLID4/uImes2L6K5sbKHbo3sIVdzFgrtB/ZdHTN11bM26OLpovCMs/HF3tqz93RMobdNv63IyOau4YgKZa+U2sW+1fGT1HtBesqGjlVlLZNJVR9ZETj4fuLKjNzOgegdbYFV9jIyP6JDi/9c6oyFRUI1anSWZcDFL+74Y4h4okAcbDgooczxBf3QlIJQdFVs9GOPCoIwmZ29c4VmBvESlRnjtXho/6sNQXlnLsG4v4GCzL7P1YOOf9FqV8XZuXJrEsTVJjDdYJdia6F3G/GRe+lRhReM42qlHqLKZpzjSFwIDAQAB'); // public key
$plaintext = 'hello world';
$rsa->setEncryptionMode(CRYPT_RSA_ENCRYPTION_PKCS1);
$ciphertext = $rsa->encrypt($plaintext);
这篇关于使用我自己的密钥文件进行RSP加密的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文