Simple3Des VB.net into PHP HELP

Public Sub EncryptFile(ByVal tmpAttFile As String, ByVal tmpPass As String, ByVal tmpText As String)
        Try
            Dim wrapper As New Simple3Des(tmpPass)
            Dim cipherText As String = wrapper.EncryptData(tmpText)
            My.Computer.FileSystem.WriteAllText(Path_SendFile & tmpAttFile, tmpText, False)
        Catch ex As Exception
            MsgBox("Proses Create File dan Encrypsi Gagal. Harap Close Dahulu Modul Transaksi", MsgBoxStyle.Information, "Error")
        End Try
    End Sub


Public NotInheritable Class Simple3Des
        Private TripleDes As New TripleDESCryptoServiceProvider

        Private Function TruncateHash(
        ByVal key As String,
        ByVal length As Integer) As Byte()

            Dim sha1 As New SHA1CryptoServiceProvider

            ' Hash the key.
            Dim keyBytes() As Byte =
                System.Text.Encoding.Unicode.GetBytes(key)
            Dim hash() As Byte = sha1.ComputeHash(keyBytes)

            ' Truncate or pad the hash.
            ReDim Preserve hash(length - 1)
            Return hash
        End Function

        Sub New(ByVal key As String)
            ' Initialize the crypto provider.
            TripleDes.Key = TruncateHash(key, TripleDes.KeySize \ 8)
            TripleDes.IV = TruncateHash("", TripleDes.BlockSize \ 8)
        End Sub

Public Function EncryptData(
    ByVal plaintext As String) As String

            ' Convert the plaintext string to a byte array.
            Dim plaintextBytes() As Byte =
                System.Text.Encoding.Unicode.GetBytes(plaintext)

            ' Create the stream.
            Dim ms As New System.IO.MemoryStream
            ' Create the encoder to write to the stream.
            Dim encStream As New CryptoStream(ms,
                TripleDes.CreateEncryptor(),
                System.Security.Cryptography.CryptoStreamMode.Write)

            ' Use the crypto stream to write the byte array to the stream.
            encStream.Write(plaintextBytes, 0, plaintextBytes.Length)
            encStream.FlushFinalBlock()

            ' Convert the encrypted stream to a printable string.
            Return Convert.ToBase64String(ms.ToArray)
        End Function

Open in new window


public static function encrypt($message, $key)
{
  $mac_algorithm = 'sha1';
  $enc_algorithm = MCRYPT_RIJNDAEL_256;
  $enc_mode = MCRYPT_MODE_CBC;
  $mac = hash_hmac($mac_algorithm, $message, $key, true);
  $mac = substr($mac, 0, ceil(static::getMacAlgoBlockSize($mac_algorithm)/8));
  $message= $mac . $message;

  $iv_size = mcrypt_get_iv_size($enc_algorithm, $enc_mode);
  $iv = mcrypt_create_iv($iv_size, MCRYPT_RAND);

  $ciphertext = mcrypt_encrypt($enc_algorithm, $key,
   $message, $enc_mode, $iv);

  return base64_encode($iv . $ciphertext);
}

Open in new window



Someone can help me to convert VB.net into PHP ?
San LieAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

David Johnson, CD, MVPOwnerCommented:
it is never good to try and transpose code from one language to another
here is an example of a working php solution https://github.com/iam-raihan/3DES-ECB-Cryptography-in-PHP
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
David Johnson, CD, MVPOwnerCommented:
solution offered with no response from author
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Encryption

From novice to tech pro — start learning today.