VB.net encryption method to PHP
up vote
0
down vote
favorite
I have received a method in VB.net and now it is my task to make the same in PHP.
The code vb.net is:
Public Function AES_Encrypt(ByVal input As String, ByVal salt As String) As String
Dim AES As New System.Security.Cryptography.RijndaelManaged
Dim Hash_AES As New System.Security.Cryptography.MD5CryptoServiceProvider
Dim encrypted As String = ""
Try
Dim hash(31) As Byte
Dim temp As Byte() = Hash_AES.ComputeHash(System.Text.ASCIIEncoding.ASCII.GetBytes(salt))
Array.Copy(temp, 0, hash, 0, 16)
Array.Copy(temp, 0, hash, 15, 16)
AES.Key = hash
AES.Mode = Security.Cryptography.CipherMode.ECB
Dim DESEncrypter As System.Security.Cryptography.ICryptoTransform = AES.CreateEncryptor
Dim Buffer As Byte() = System.Text.ASCIIEncoding.ASCII.GetBytes(input)
encrypted = Convert.ToBase64String(DESEncrypter.TransformFinalBlock(Buffer, 0, Buffer.Length))
Return encrypted
Catch ex As Exception
Debugger.Break()
Return ""
End Try
End Function
I have tried a couple of things in PHP but I am stuck.
I think the problem is with the translation with this method: DESEncrypter.TransformFinalBlock.
My PHP code is:
function mc_encrypt($encrypt, $mc_key){
$passcrypt = (mcrypt_encrypt(MCRYPT_RIJNDAEL_256, $mc_key, $encrypt, MCRYPT_MODE_ECB));
$encoded = base64_encode($passcrypt);
return $encoded;
}
The keys are the same in both methods.
So in vb.net AES.Key is equal to the $mc_key in PHP.
Update:
Changed my php code to
function mc_encrypt($encrypt, $mc_key){
echo $mc_key;
$passcrypt = (mcrypt_encrypt(MCRYPT_RIJNDAEL_128, base64_decode($mc_key), $encrypt, MCRYPT_MODE_ECB));
$encoded = base64_encode($passcrypt);
return $encoded;
}
Now the result in VB.net is
MTbXbSE5J/9yh6EsrgeuNZYffQudFTXW0nTd/X8IOAtpnW971JQlpqF0+B9O/hfW
and in PHP:
MTbXbSE5J/9yh6EsrgeuNZYffQudFTXW0nTd/X8IOAv8342+hhksKR6MVgVeXGWb
php vb.net encryption aes
|
show 3 more comments
up vote
0
down vote
favorite
I have received a method in VB.net and now it is my task to make the same in PHP.
The code vb.net is:
Public Function AES_Encrypt(ByVal input As String, ByVal salt As String) As String
Dim AES As New System.Security.Cryptography.RijndaelManaged
Dim Hash_AES As New System.Security.Cryptography.MD5CryptoServiceProvider
Dim encrypted As String = ""
Try
Dim hash(31) As Byte
Dim temp As Byte() = Hash_AES.ComputeHash(System.Text.ASCIIEncoding.ASCII.GetBytes(salt))
Array.Copy(temp, 0, hash, 0, 16)
Array.Copy(temp, 0, hash, 15, 16)
AES.Key = hash
AES.Mode = Security.Cryptography.CipherMode.ECB
Dim DESEncrypter As System.Security.Cryptography.ICryptoTransform = AES.CreateEncryptor
Dim Buffer As Byte() = System.Text.ASCIIEncoding.ASCII.GetBytes(input)
encrypted = Convert.ToBase64String(DESEncrypter.TransformFinalBlock(Buffer, 0, Buffer.Length))
Return encrypted
Catch ex As Exception
Debugger.Break()
Return ""
End Try
End Function
I have tried a couple of things in PHP but I am stuck.
I think the problem is with the translation with this method: DESEncrypter.TransformFinalBlock.
My PHP code is:
function mc_encrypt($encrypt, $mc_key){
$passcrypt = (mcrypt_encrypt(MCRYPT_RIJNDAEL_256, $mc_key, $encrypt, MCRYPT_MODE_ECB));
$encoded = base64_encode($passcrypt);
return $encoded;
}
The keys are the same in both methods.
So in vb.net AES.Key is equal to the $mc_key in PHP.
Update:
Changed my php code to
function mc_encrypt($encrypt, $mc_key){
echo $mc_key;
$passcrypt = (mcrypt_encrypt(MCRYPT_RIJNDAEL_128, base64_decode($mc_key), $encrypt, MCRYPT_MODE_ECB));
$encoded = base64_encode($passcrypt);
return $encoded;
}
Now the result in VB.net is
MTbXbSE5J/9yh6EsrgeuNZYffQudFTXW0nTd/X8IOAtpnW971JQlpqF0+B9O/hfW
and in PHP:
MTbXbSE5J/9yh6EsrgeuNZYffQudFTXW0nTd/X8IOAv8342+hhksKR6MVgVeXGWb
php vb.net encryption aes
What do you mean with hash function, i am new to encryption and have around 0 knowledge about it. The orginal code is not mine and i can not change it.
– Torierja
Nov 9 at 13:38
Yeah that is used to create the key, but i said in vb.net AES.Key is equal to the $mc_key in php. So i already have the key hashed in php!
– Torierja
Nov 9 at 13:43
Ah, my bad. Apologies. TryMCRYPT_RIJNDAEL_128, the last number indicates the block size, not the key size. Removed previous comments.
– Maarten Bodewes
Nov 9 at 13:45
I did some googling and saw that in vb net System.Security.Cryptography.RijndaelManaged the default rijndael 256 is. But i gave it a try and it is still different results
– Torierja
Nov 9 at 13:48
Citation needed. I don't believe that it is. AES has 128 bit block size.
– Maarten Bodewes
Nov 9 at 13:50
|
show 3 more comments
up vote
0
down vote
favorite
up vote
0
down vote
favorite
I have received a method in VB.net and now it is my task to make the same in PHP.
The code vb.net is:
Public Function AES_Encrypt(ByVal input As String, ByVal salt As String) As String
Dim AES As New System.Security.Cryptography.RijndaelManaged
Dim Hash_AES As New System.Security.Cryptography.MD5CryptoServiceProvider
Dim encrypted As String = ""
Try
Dim hash(31) As Byte
Dim temp As Byte() = Hash_AES.ComputeHash(System.Text.ASCIIEncoding.ASCII.GetBytes(salt))
Array.Copy(temp, 0, hash, 0, 16)
Array.Copy(temp, 0, hash, 15, 16)
AES.Key = hash
AES.Mode = Security.Cryptography.CipherMode.ECB
Dim DESEncrypter As System.Security.Cryptography.ICryptoTransform = AES.CreateEncryptor
Dim Buffer As Byte() = System.Text.ASCIIEncoding.ASCII.GetBytes(input)
encrypted = Convert.ToBase64String(DESEncrypter.TransformFinalBlock(Buffer, 0, Buffer.Length))
Return encrypted
Catch ex As Exception
Debugger.Break()
Return ""
End Try
End Function
I have tried a couple of things in PHP but I am stuck.
I think the problem is with the translation with this method: DESEncrypter.TransformFinalBlock.
My PHP code is:
function mc_encrypt($encrypt, $mc_key){
$passcrypt = (mcrypt_encrypt(MCRYPT_RIJNDAEL_256, $mc_key, $encrypt, MCRYPT_MODE_ECB));
$encoded = base64_encode($passcrypt);
return $encoded;
}
The keys are the same in both methods.
So in vb.net AES.Key is equal to the $mc_key in PHP.
Update:
Changed my php code to
function mc_encrypt($encrypt, $mc_key){
echo $mc_key;
$passcrypt = (mcrypt_encrypt(MCRYPT_RIJNDAEL_128, base64_decode($mc_key), $encrypt, MCRYPT_MODE_ECB));
$encoded = base64_encode($passcrypt);
return $encoded;
}
Now the result in VB.net is
MTbXbSE5J/9yh6EsrgeuNZYffQudFTXW0nTd/X8IOAtpnW971JQlpqF0+B9O/hfW
and in PHP:
MTbXbSE5J/9yh6EsrgeuNZYffQudFTXW0nTd/X8IOAv8342+hhksKR6MVgVeXGWb
php vb.net encryption aes
I have received a method in VB.net and now it is my task to make the same in PHP.
The code vb.net is:
Public Function AES_Encrypt(ByVal input As String, ByVal salt As String) As String
Dim AES As New System.Security.Cryptography.RijndaelManaged
Dim Hash_AES As New System.Security.Cryptography.MD5CryptoServiceProvider
Dim encrypted As String = ""
Try
Dim hash(31) As Byte
Dim temp As Byte() = Hash_AES.ComputeHash(System.Text.ASCIIEncoding.ASCII.GetBytes(salt))
Array.Copy(temp, 0, hash, 0, 16)
Array.Copy(temp, 0, hash, 15, 16)
AES.Key = hash
AES.Mode = Security.Cryptography.CipherMode.ECB
Dim DESEncrypter As System.Security.Cryptography.ICryptoTransform = AES.CreateEncryptor
Dim Buffer As Byte() = System.Text.ASCIIEncoding.ASCII.GetBytes(input)
encrypted = Convert.ToBase64String(DESEncrypter.TransformFinalBlock(Buffer, 0, Buffer.Length))
Return encrypted
Catch ex As Exception
Debugger.Break()
Return ""
End Try
End Function
I have tried a couple of things in PHP but I am stuck.
I think the problem is with the translation with this method: DESEncrypter.TransformFinalBlock.
My PHP code is:
function mc_encrypt($encrypt, $mc_key){
$passcrypt = (mcrypt_encrypt(MCRYPT_RIJNDAEL_256, $mc_key, $encrypt, MCRYPT_MODE_ECB));
$encoded = base64_encode($passcrypt);
return $encoded;
}
The keys are the same in both methods.
So in vb.net AES.Key is equal to the $mc_key in PHP.
Update:
Changed my php code to
function mc_encrypt($encrypt, $mc_key){
echo $mc_key;
$passcrypt = (mcrypt_encrypt(MCRYPT_RIJNDAEL_128, base64_decode($mc_key), $encrypt, MCRYPT_MODE_ECB));
$encoded = base64_encode($passcrypt);
return $encoded;
}
Now the result in VB.net is
MTbXbSE5J/9yh6EsrgeuNZYffQudFTXW0nTd/X8IOAtpnW971JQlpqF0+B9O/hfW
and in PHP:
MTbXbSE5J/9yh6EsrgeuNZYffQudFTXW0nTd/X8IOAv8342+hhksKR6MVgVeXGWb
php vb.net encryption aes
php vb.net encryption aes
edited Nov 9 at 16:34
Visual Vincent
14.9k51947
14.9k51947
asked Nov 9 at 13:07
Torierja
12
12
What do you mean with hash function, i am new to encryption and have around 0 knowledge about it. The orginal code is not mine and i can not change it.
– Torierja
Nov 9 at 13:38
Yeah that is used to create the key, but i said in vb.net AES.Key is equal to the $mc_key in php. So i already have the key hashed in php!
– Torierja
Nov 9 at 13:43
Ah, my bad. Apologies. TryMCRYPT_RIJNDAEL_128, the last number indicates the block size, not the key size. Removed previous comments.
– Maarten Bodewes
Nov 9 at 13:45
I did some googling and saw that in vb net System.Security.Cryptography.RijndaelManaged the default rijndael 256 is. But i gave it a try and it is still different results
– Torierja
Nov 9 at 13:48
Citation needed. I don't believe that it is. AES has 128 bit block size.
– Maarten Bodewes
Nov 9 at 13:50
|
show 3 more comments
What do you mean with hash function, i am new to encryption and have around 0 knowledge about it. The orginal code is not mine and i can not change it.
– Torierja
Nov 9 at 13:38
Yeah that is used to create the key, but i said in vb.net AES.Key is equal to the $mc_key in php. So i already have the key hashed in php!
– Torierja
Nov 9 at 13:43
Ah, my bad. Apologies. TryMCRYPT_RIJNDAEL_128, the last number indicates the block size, not the key size. Removed previous comments.
– Maarten Bodewes
Nov 9 at 13:45
I did some googling and saw that in vb net System.Security.Cryptography.RijndaelManaged the default rijndael 256 is. But i gave it a try and it is still different results
– Torierja
Nov 9 at 13:48
Citation needed. I don't believe that it is. AES has 128 bit block size.
– Maarten Bodewes
Nov 9 at 13:50
What do you mean with hash function, i am new to encryption and have around 0 knowledge about it. The orginal code is not mine and i can not change it.
– Torierja
Nov 9 at 13:38
What do you mean with hash function, i am new to encryption and have around 0 knowledge about it. The orginal code is not mine and i can not change it.
– Torierja
Nov 9 at 13:38
Yeah that is used to create the key, but i said in vb.net AES.Key is equal to the $mc_key in php. So i already have the key hashed in php!
– Torierja
Nov 9 at 13:43
Yeah that is used to create the key, but i said in vb.net AES.Key is equal to the $mc_key in php. So i already have the key hashed in php!
– Torierja
Nov 9 at 13:43
Ah, my bad. Apologies. Try
MCRYPT_RIJNDAEL_128, the last number indicates the block size, not the key size. Removed previous comments.– Maarten Bodewes
Nov 9 at 13:45
Ah, my bad. Apologies. Try
MCRYPT_RIJNDAEL_128, the last number indicates the block size, not the key size. Removed previous comments.– Maarten Bodewes
Nov 9 at 13:45
I did some googling and saw that in vb net System.Security.Cryptography.RijndaelManaged the default rijndael 256 is. But i gave it a try and it is still different results
– Torierja
Nov 9 at 13:48
I did some googling and saw that in vb net System.Security.Cryptography.RijndaelManaged the default rijndael 256 is. But i gave it a try and it is still different results
– Torierja
Nov 9 at 13:48
Citation needed. I don't believe that it is. AES has 128 bit block size.
– Maarten Bodewes
Nov 9 at 13:50
Citation needed. I don't believe that it is. AES has 128 bit block size.
– Maarten Bodewes
Nov 9 at 13:50
|
show 3 more comments
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53226302%2fvb-net-encryption-method-to-php%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
What do you mean with hash function, i am new to encryption and have around 0 knowledge about it. The orginal code is not mine and i can not change it.
– Torierja
Nov 9 at 13:38
Yeah that is used to create the key, but i said in vb.net AES.Key is equal to the $mc_key in php. So i already have the key hashed in php!
– Torierja
Nov 9 at 13:43
Ah, my bad. Apologies. Try
MCRYPT_RIJNDAEL_128, the last number indicates the block size, not the key size. Removed previous comments.– Maarten Bodewes
Nov 9 at 13:45
I did some googling and saw that in vb net System.Security.Cryptography.RijndaelManaged the default rijndael 256 is. But i gave it a try and it is still different results
– Torierja
Nov 9 at 13:48
Citation needed. I don't believe that it is. AES has 128 bit block size.
– Maarten Bodewes
Nov 9 at 13:50