' 發展單位:風禹科技驗證有限公司 ' 撰寫人:鄭子璉(Tzu-Lien, Cheng, 璉璉) ,成大水博肄,微軟最有價值專家 ' Web: http://tlcheng.twbbs.org/TLCheng/ E-Mail: qvb3377@ms5.hinet.net ' -------------------------------------------------------------------------------------- Module modSecurityTools Friend Function MyDESEncrypt(ByVal objValue As Object, ByVal desKey As Byte(), ByVal desIV As Byte()) As Byte() Return MyDESEncryptBytes(ObjectToByte(objValue), desKey, desIV) End Function Friend Function MyDESEncryptBytes(ByVal arrBytes As Byte(), ByVal desKey As Byte(), ByVal desIV As Byte()) As Byte() Dim memStream As New IO.MemoryStream Dim ubb As Integer = UBound(arrBytes) Dim des As New System.Security.Cryptography.DESCryptoServiceProvider() Dim encStream As New System.Security.Cryptography.CryptoStream(memStream, des.CreateEncryptor(desKey, desIV), System.Security.Cryptography.CryptoStreamMode.Write) With encStream .Write(arrBytes, 0, ubb + 1) .FlushFinalBlock() .Close() End With Dim outBytes As Byte() = memStream.ToArray Return outBytes End Function Friend Function MyDESDecryptBytes(ByVal arrBytes As Byte(), ByVal desKey As Byte(), ByVal desIV As Byte()) As Byte() Dim memStream As New IO.MemoryStream Dim ubb As Integer = UBound(arrBytes) Dim des As New System.Security.Cryptography.DESCryptoServiceProvider() Dim decStream As New System.Security.Cryptography.CryptoStream(memStream, des.CreateDecryptor(desKey, desIV), System.Security.Cryptography.CryptoStreamMode.Write) With decStream .Write(arrBytes, 0, ubb + 1) .FlushFinalBlock() .Close() End With Dim outBytes As Byte() = memStream.ToArray Return outBytes End Function Friend Function MyDESDecrypt(ByVal objValue As Object, ByVal desKey As Byte(), ByVal desIV As Byte(), Optional ByVal nVarType As VariantType = VariantType.Array Or VariantType.Byte, Optional ByVal bBigEndian As Boolean = False) As Object Return ByteToVariant(MyDESDecryptBytes(ObjectToByte(objValue), desKey, desIV), nVarType, bBigEndian) End Function End Module