-
Rsa
加密算法加密长度限制是
117
字节,下面展示的是不限制长度
rsa
改造方法
包含的有加密解密
加密的内容与原类型比较是否所有值都相等以及一个单元测试
public
class
RsaHelper
{
public
static
string
PubKey
=”
自己用下面生成的
”
;
//
公钥
public
static
string
PriKey
=”
自己用下面生成的
”
;
//
私钥
public
struct
RsaKey
{
public
string
PublicKey {
get
;
set
; }
public
string
PrivateKey {
get
;
set
; }
}
///
///
创建公钥私钥
///
///
static
public
RsaKey
GEN_Key()
{
var
rsa =
new
RSACryptoServiceProvider
();
return
new
RsaKey
()
{
//
写死加快执行速度
//PublicKey = tring(false),
//
生成公钥
自己生成填到上面
//PrivateKey = tring(true)
//
生成私钥
自己生成填到上面
};
}
///
///
解密
///
///
要解密的字符串
///
私钥
///
public
static
string
RsaDecrypt(
string
encryptedInput,
string
privateKey)
{
if
(
string
.IsNullOrEmpty(encrypt
edInput))
{
return
string
.Empty;
}
if
(
s
tring
.IsNullOrWhiteSpace(privateKey))
{
throw
new
ArgumentExcep
tion
(
);
}
using
(
var
rsaProvider =
new
RSACryptoServiceProvider
())
{
var
inputBytes =
Convert
.FromBase64String(enc
ryptedInput);
lString(privateKey);
int
bufferSize = e / 8;
var
buffer =
new
byte
[bufferSize];
using
(
MemoryStream
inputStream =
new
MemoryStream
(inputBytes),
outputStream =
new
MemoryStream
())
{
while
(
true
)
{
int
readSize = (buffer, 0,
bufferSize);
if
(readSize <=
0)
{
break
;
}
var
temp =
new
byte
[readSize];
Array
.Copy(buffer, 0, temp,
0, readSize);
var
rawBytes =
t(temp,
false
);
(rawBytes, 0, );
}
return
Encoding
.ing(y());
}
}
}
///
///
加密
///
///
要加密的字符串
///
公钥
///
public
static
string
RsaEncrypt(
string
rawInput,
string
publicKey)
{
if
(
s
tring
.IsNullOrEmpty(rawInput))
{
return
string
.Empty;
}
if
(
s
tring
.IsNullOrWhiteSpace(publicKey))
{