0

Was hoping someone would be able to help me out.

I desperately need this VB.NET code converted to PHP.

This is the Instructions I received:

To test your encryption, encrypt the following word with these keys and check if you get the same result:

Text to encrypt: MyPassword
Salt key: *&^%$#@!
PBE Key: FWV70700
PBE IV: WEBSV

NOTE:
Encrypted text: A+V3JATKUt/T91HiF23eOA==
Following is a short VB.Net code snippet that will do the encryption, as we need it. The VB program has a form (From1) with two text boxes (TextBox1 and TextBox2) and one button (Button1):

VB.NET Function:

Imports System
Imports System.IO
Imports System.Xml
Imports System.Text
Imports System.Security.Cryptography
Public Class Form1
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    TextBox2.Text = EncryptText(TextBox1.Text)
End Sub
Public Shared Function EncryptText(ByVal strText As String) As String
    Dim pdbPassword As PasswordDeriveBytes
    Dim pdbIV As PasswordDeriveBytes
    Dim DES As New DESCryptoServiceProvider
    Dim salt() As Byte = {Asc("*"), Asc("&"), Asc("^"), Asc("%"), Asc("$"), Asc("#"), Asc("@"), Asc("!")}
    Dim ms As New System.IO.MemoryStream
    Dim cs As CryptoStream
    Dim plainText As String = strText
    Dim plainBytes() As Byte
    plainBytes = System.Text.Encoding.UTF8.GetBytes(plainText)
    pdbPassword = New PasswordDeriveBytes("FWV70700", salt)
    pdbPassword.HashName = "SHA1"
    pdbPassword.IterationCount = 1000
    DES.Key = pdbPassword.GetBytes(8)

    pdbIV = New PasswordDeriveBytes("WEBSV", salt)
    pdbIV.HashName = "SHA1"
    pdbIV.IterationCount = 1000
    DES.IV = pdbIV.GetBytes(8)
    cs = New CryptoStream(ms, DES.CreateEncryptor, CryptoStreamMode.Write)
    cs.Write(plainBytes, 0, plainBytes.Length)
    cs.FlushFinalBlock()
    Return Convert.ToBase64String(ms.ToArray)
End Function

Could someone PLEASE convert this to PHP for me?

2
  • 1
    Stack Overflow is not here to do your work. Commented Dec 2, 2011 at 11:37
  • If you don't want to do this yourself try rent-a-coder? Commented Dec 2, 2011 at 15:06

1 Answer 1

1

You need to find the according functions that do the same in PHP and then code it in PHP. It's best to do this step by step so you can compare if it's already working or not. As you have the vb.net code you can do this.

Sometimes functions vary a bit between .net and PHP, so there might be specific issues you need to take care about, so better do everything step by step and double checked.

See as well this related question: Same string, different SHA1 hash values obtained from VB.net and PHP.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.