我正在处理标准的3 3DES 128位,用于加密和解密字符串。它在两个不同的环境中实现:经典ASP (VB6)和.Net。
我认为3 3DES是标准的,但是我不能使它在这两者之间兼容(capicom和.Net)。谷歌一遍后,我意识到capicom有一些自己的定制魔法。
据我所知,3 3DES需要两个指定的128位(8字节)密钥(密码)和8字节的"IV"。所以,我找不到可以在capicom中指定"IV“的8个字节的地方,因此,我怀疑这是造成差异的原因。
.Net System.Security.Cryptography
Dim m_des As New TripleDESCryptoServiceProvider
...
Private ReadOnly str_key As String = "MyPwd1234567890p"
Private ReadOnly iv() As Byte = {8, 7, 6, 5, 4, 3, 2, 1}
Private m_utf8 As New UTF8Encoding
Private m_key() As Byte
Private m_iv() As Byte
Public Sub New(ByVal key() As Byte, ByVal iv() As Byte)
Me.m_key = key
Me.m_iv = iv
End Sub
' VB.NET to convert a string to a byte array
Public Shared Function StrToByteArray(ByVal str As String) As Byte()
Dim encoding As New System.Text.UTF8Encoding()
Return encoding.GetBytes(str)
End Function
Public Function Encrypt(ByVal input() As Byte) As Byte()
Return Transform(input, m_des.CreateEncryptor(StrToByteArray(str_key), m_iv))
End FunctionVB6环境中的Capicom:
Dim DecryptData
Set DecryptData = CreateObject("CAPICOM.EncryptedData")
Dim sDAta
sData = "Hello World"
DecryptData.Algorithm.KeyLength = CAPICOM_ENCRYPTION_KEY_LENGTH_128_BITS
DecryptData.Algorithm.Name = CAPICOM_ENCRYPTION_ALGORITHM_3DES
DecryptData.SetSecret("MyPwd1234567890p")
result = DecryptData.Decrypt(sData)希望你能帮我提供一些想法。
https://stackoverflow.com/questions/6329806
复制相似问题