使用PHP解密文件(3DES)

时间:2013-09-04 16:39:38

标签: php vb.net encryption

我需要用PHP解密文件,因为它是在VB.net中加密的,反之亦然。

Imports System.IO
Imports System.Security.Cryptography
Imports System.Text

Public Class EncryptionAndDecryptionClass

    Public Key(15) As Byte
    Private Vector() As Byte = {&H12, &H44, &H16, &HEE, &H88, &H15, &HDD, &H41, &H12, &H44, &H16, &HEE, &H88, &H15, &HDD, &H41}

    Function Decrypt(ByVal Data() As Byte) As String
        Dim MemoryStream As New MemoryStream(Data)
        Dim csDecrypt As New CryptoStream(MemoryStream, New TripleDESCryptoServiceProvider().CreateDecryptor(Key, Vector), CryptoStreamMode.Read)
        Dim fromEncrypt(Data.Length) As Byte
        csDecrypt.Read(fromEncrypt, 0, fromEncrypt.Length)
        Return New UTF8Encoding().GetString(fromEncrypt)
    End Function

    Function Encrypt(ByVal Data As String) As Byte()
        Dim MemoryStream As New MemoryStream
        Dim cStream As New CryptoStream(MemoryStream, New TripleDESCryptoServiceProvider().CreateEncryptor(Key, Vector), CryptoStreamMode.Write)
        Dim toEncrypt As Byte() = New UTF8Encoding().GetBytes(Data)
        cStream.Write(toEncrypt, 0, toEncrypt.Length)
        cStream.FlushFinalBlock()
        Dim ret As Byte() = MemoryStream.ToArray()
        cStream.Close()
        MemoryStream.Close()
        Return ret
    End Function

    Sub CreateKey(ByVal strKey As String)
        Dim arrByte(15) As Byte
        Dim AscEncod As New UTF8Encoding
        Dim i As Integer = 0
        AscEncod.GetBytes(strKey, i, strKey.Length, arrByte, i)
        Dim hashSha As New SHA1CryptoServiceProvider
        Dim arrHash() As Byte = hashSha.ComputeHash(arrByte)
        For i = 0 To 15
            Key(i) = arrHash(i)
        Next i
    End Sub
End Class

这是我在VB中的代码,它加密和解密字符串,但不能在PHP代码中执行相同的操作。我想用PHP做到这一点。

您是否知道任何可以使用上述代码读取加密数据的PHP代码?

0 个答案:

没有答案