35 lines
1.2 KiB
Plaintext
35 lines
1.2 KiB
Plaintext
-- 使用私钥进行解密的函数
|
|
fn decryptWithPrivateKey encryptedData privateKey =
|
|
(
|
|
rsaProvider = dotnetobject "System.Security.Cryptography.RSACryptoServiceProvider"
|
|
rsaProvider.FromXmlString(privateKey)
|
|
methodprivatekey = (dotnetclass "System.Security.Cryptography.RSAEncryptionPadding").Pkcs1
|
|
|
|
try(
|
|
-- 使用私钥解密字节数组
|
|
decryptedBytes = rsaProvider.Decrypt encryptedData methodprivatekey
|
|
|
|
-- 将字节数组转换为文本
|
|
decryptedText = (dotnetclass "System.Text.Encoding").UTF8.GetString(decryptedBytes)
|
|
|
|
return decryptedText)catch(return "解密错误!!!")
|
|
)
|
|
|
|
-- 从文件中读取加密后的数据
|
|
encryptedDataFilePath = getFilenamePath(getThisScriptFilename()) + "data.txt"
|
|
streamReader = dotnetobject "System.IO.StreamReader" encryptedDataFilePath
|
|
|
|
encryptedData = (dotnetclass "System.Convert").FromBase64String(streamReader.ReadLine())
|
|
streamReader.Close()
|
|
|
|
-- 从文件中读取私钥
|
|
privateKeyFilePath = getFilenamePath(getThisScriptFilename()) + "privateKey.xml"
|
|
streamReader = dotnetobject "System.IO.StreamReader" privateKeyFilePath
|
|
privateKey = streamReader.ReadToEnd()
|
|
streamReader.Close()
|
|
|
|
-- 示例:使用私钥解密之前加密的数据
|
|
decryptedText = decryptWithPrivateKey encryptedData privateKey
|
|
|
|
-- 输出解密后的数据
|
|
print decryptedText |