VB.net encryption method to PHP











up vote
0
down vote

favorite
1












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









share|improve this question
























  • 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

















up vote
0
down vote

favorite
1












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









share|improve this question
























  • 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















up vote
0
down vote

favorite
1









up vote
0
down vote

favorite
1






1





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









share|improve this question















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






share|improve this question















share|improve this question













share|improve this question




share|improve this question








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. 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




















  • 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


















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



















active

oldest

votes











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














 

draft saved


draft discarded


















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






























active

oldest

votes













active

oldest

votes









active

oldest

votes






active

oldest

votes
















 

draft saved


draft discarded



















































 


draft saved


draft discarded














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





















































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







Popular posts from this blog

Landwehr

Reims

Schenkenzell