求在C#、ASP.NET环境下使用AspEncrypt组件方法。内附VB语言ASP环境下部分代码。
以下是VB语言,ASP环境下部分代码。Function EncryptString(strStringToEncrypt, strPassword, ByRef strEncryptedString )
On Error Resume Next
Dim objCryptoMgr
Dim objCryptoContext
Dim objCryptoKey
Dim objCryptoBlob
Err.Clear
' Encrypt text, place encrypted data into a blob
Set objCryptoMgr = Server.CreateObject("Persits.CryptoManager")
Set objCryptoContext = objCryptoMgr.OpenContext(gstrCompanyName, True)
Set objCryptoKey = objCryptoContext.GenerateKeyFromPassword(strPassword,,,40)
Set objCryptoBlob = objCryptoKey.EncryptText( strStringToEncrypt )
objCryptoKey.EffectiveLength = 40
' CryptoBlob presents data in three formats: Hex, Base64 and Binary.
strEncryptedString = objCryptoBlob.Hex
If Err.number <> 0 Then
strEncryptedString = ""
End If
Set objCryptoBlob = Nothing
Set objCryptoKey = Nothing
Set objCryptoContext = Nothing
Set objCryptoMgr = Nothing
End Function
'***********************************************************************************
' This Persits AspEncrypt function Decrypts a string using the input password.
'***********************************************************************************
Function DecryptString(strStringToDecrypt, strPassword, ByRef strDecryptedString)
On Error Resume Next
Dim objCryptoMgr
Dim objCryptoContext
Dim objCryptoKey
Dim objCryptoBlob
Err.Clear
Set objCryptoMgr = Server.CreateObject("Persits.CryptoManager")
Set objCryptoContext = objCryptoMgr.OpenContext("mycontainer", True)
Set objCryptoKey = objCryptoContext.GenerateKeyFromPassword(strPassword,,,40)
Set objCryptoBlob = objCryptoMgr.CreateBlob
objCryptoKey.EffectiveLength = 40
objCryptoBlob.Hex = strStringToDecrypt
strDecryptedString = objCryptoKey.DecryptText(objCryptoBlob)
If Err.number = 0 Then
DecryptString = True
Else
DecryptString = False
strDecryptedString = strStringToDecrypt 'Reverse to original string
End If
Set objCryptoBlob = Nothing
Set objCryptoKey = Nothing
Set objCryptoContext = Nothing
Set objCryptoMgr = Nothing
End Function --------------------编程问答--------------------
补充:.NET技术 , ASP.NET