string Decrypt(string cipher)
{
int
index
=
cipher.IndexOf(
'.'
);
string part1
=
cipher.Remove(index);
string part2
=
cipher.Substring(index
+
1
);
byte[] keyBytes
=
DecryptPkcs1(USED_KEY, Convert.FromBase64String(part1));
string result
=
Encoding.UTF8.GetString(DecryptTripleDES(keyBytes, Convert.FromBase64String(part2)));
return
result;
}
byte[] DecryptPkcs1(string key, byte[] data)
{
if
(data
=
=
null || data.Length
=
=
0
)
{
throw new NotSupportedException();
}
Pkcs1Encoding pkcs1Encoding
=
new Pkcs1Encoding(new RsaEngine());
RsaPrivateCrtKeyParameters parameters
=
(RsaPrivateCrtKeyParameters)PrivateKeyFactory.CreateKey(Convert.FromBase64String(key));
pkcs1Encoding.Init(false, parameters);
return
pkcs1Encoding.ProcessBlock(data,
0
, data.Length);
}
byte[] DecryptTripleDES(byte[] key, byte[] data)
{
byte[] rgbIV
=
new byte[] {
1
,
2
,
3
,
4
,
5
,
6
,
7
,
8
};
Stream stream
=
new CryptoStream(new MemoryStream(data), new TripleDESCryptoServiceProvider
{
Mode
=
CipherMode.ECB,
Padding
=
PaddingMode.PKCS7
}.CreateDecryptor(key, rgbIV), CryptoStreamMode.Read);
byte[] array
=
new byte[data.Length];
stream.Read(array,
0
, array.Length);
return
array;
}