I'm looking to convert this function from PHP to VB. Could anyone help me understand why the output is not correct?
//get img
$img = file_get_contents('https://www.random.org/analysis/randbitmap-rdo-section.png');
//pad
$blocksize = 16;
$pad = $blocksize - (strlen($img) % $blocksize);
$paddedimg = $img . str_repeat(chr($pad), $pad);
//encrypt
$data = mcrypt_encrypt(MCRYPT_RIJNDAEL_128, 'abcdefghijklmnop', $paddedimg, MCRYPT_MODE_ECB);
//output
echo base64_encode($data);
The above outputs;
wYkugZmmsCHNwFOr7sAgk6yUU2I+2rOtBmXAIcPleue+dT4zIvkSA6UYmW6tickeoIbyCylxrb5n ...
[rest truncated but goes on and total is 29484 characters]
Here's what I have in VB;
Public Sub GetBase64EncryptedImg()
Dim Img As Byte() = Nothing
Using wc As New WebClient
Img = wc.DownloadData("https://www.random.org/analysis/randbitmap-rdo-section.png")
End Using
MsgBox(EncryptECB(Img))
End Sub
Public Function EncryptECB(Data As Byte()) As String
Dim Key As Byte() = Encoding.UTF8.GetBytes("abcdefghijklmnop")
Dim Encrypted As Byte() = Nothing
Using rj As New RijndaelManaged()
Try
rj.Padding = PaddingMode.PKCS7
rj.Mode = CipherMode.ECB
rj.KeySize = 128
rj.BlockSize = 128
rj.Key = Key
Dim ms As New MemoryStream()
Using cs As New CryptoStream(ms, rj.CreateEncryptor(rj.Key, rj.IV), CryptoStreamMode.Write)
Using sr As New StreamWriter(cs)
sr.Write(Data)
End Using
Encrypted = ms.ToArray()
End Using
Finally
rj.Clear()
End Try
End Using
Return Convert.ToBase64String(Encrypted)
End Function
The VB outputs;
pVngUaXYYv1tJSPzjDuwKw==
That's it, nowhere close to the right number of characters. Where am I going wrong here?
EDIT: Re being marked as duplicate, that question/answer gives back a base64 encoded string. mcrypt_encrypt doesn't, so I'm not sure how to apply the code in that answer.
EDIT2: That duplicate gives uses an IV value whereas the code above doesn't. Would that not differentiate the two to deserve a unique answer? Or is it as simple as removing the line setting the IV property of the RijndaelManaged object?
EDIT3: Completely reworked the question
Related
Somehow I need to generate a hash in Classic ASP which is equivalent to PHP's following function's output:
$hash = hash_hmac('SHA256', $message, pack('H*', $secret));
where $message = 'stackoverflow'; $secret = '1234567890ABCDEF';. I tried quite a lot approaches online, but none matches the PHP result:
bcb3452cd48c0f9048e64258ca24d0f3399563971d4a5dcdc531a7806b059e36
Method 1: Using dvim_brix_crypto-js-master_VB.asp online (using CrytoJS)
Function mac256(ent, key)
Dim encWA
Set encWA = ConvertUtf8StrToWordArray(ent)
Dim keyWA
Set keyWA = ConvertUtf8StrToWordArray(key)
Dim resWA
Set resWA = CryptoJS.HmacSHA256(encWA, key)
Set mac256 = resWA
End Function
Function ConvertUtf8StrToWordArray(data)
If (typename(data) = "String") Then
Set ConvertUtf8StrToWordArray = CryptoJS.enc.Utf8.parse(data)
Elseif (typename(data) = "JScriptTypeInfo") Then
On error resume next
'Set ConvertUtf8StrToWordArray = CryptoJS.enc.Utf8.parse(data.toString(CryptoJS.enc.Utf8))
Set ConvertUtf8StrToWordArray = CryptoJS.lib.WordArray.create().concat(data) 'Just assert that data is WordArray
If Err.number>0 Then
Set ConvertUtf8StrToWordArray = Nothing
End if
On error goto 0
Else
Set ConvertUtf8StrToWordArray = Nothing
End if
End Function
The script can be found here. This method gives:
c8375cf0c0db721ecc9c9b3a034284117d778ee8594285196c41d5020917f78c
Method 2: Pure Classic ASP Approach
Public Function HMAC_SHA256(prmKey, prmData)
Dim theKey : theKey = prmKey
Dim Block_Size, O_Pad, I_Pad
Block_Size = 64
O_Pad = 92 'HEX: 5c'
I_Pad = 54 'HEX: 36'
Dim iter, iter2
If Len(theKey) < Block_Size Then
For iter = 1 to Block_Size - Len(theKey)
theKey = theKey & chr(0)
Next
ElseIf Len(theKey) > Block_Size Then
theKey = SHA256(theKey)
End If
Dim o_key_pad : o_key_pad = ""
Dim i_key_pad : i_key_pad = ""
For iter = 1 to Block_Size
o_key_pad = o_key_pad & Chr(Asc(Mid(theKey,iter,1)) xor O_Pad)
i_key_pad = i_key_pad & Chr(Asc(Mid(theKey,iter,1)) xor I_Pad)
Next
HMAC_SHA256 = SHA256(o_key_pad & SHA256(i_key_pad & prmData))
End Function
result = HMAC_SHA256(secret, message)
This method gives:
bc0511316791176484c7d80bc8faaecd8388b75fb97516181ba6b361fd032531
Method 3: Using Amazon AWS's sha256.wsc (using CrytoJS)
Dim sha
Set sha = GetObject( "script:" & Server.MapPath("sha256.wsc") )
sha.hexcase = 0
result = sha.b64_hmac_sha256(secret, message)
The WSC can be found here. This method gives (same result as Method 1):
c8375cf0c0db721ecc9c9b3a034284117d778ee8594285196c41d5020917f78c
I think the problem is the pack() part, which changes the Hex string to binary. Therefore, I found a way to reproduce the pack() function in ASP:
Dim key2, hexarr, binstr
key2 = "12 34 56 78 90 AB CD EF"
hexarr = Split(key2)
ReDim binarr(UBound(hexarr))
For i = 0 To UBound(hexarr)
binarr(i) = Chr(CInt("&h" & hexarr(i)))
Next
binstr = Join(binarr, "")
where the key2 is the original secret with space added in every 2 characters. By replacing the secret with binstr, the methods now produce:
Method 1: 8ab9e595eab259acb10aa18df7fdf0ecc5ec593f97572d3a4e09f05fdd3aeb8f
Method 2: d23fcafb41d7b581fdae8c2a4a65bc3b19276a4bd367eda9e8e3de43b6a4d355
Method 3: 8ab9e595eab259acb10aa18df7fdf0ecc5ec593f97572d3a4e09f05fdd3aeb8f
None of the above results is identical to PHP's one. What did I miss now?
Check out the following example.
The only requirement with this approach is Microsoft .Net Framework 2.0 (preinstalled starting from Windows Server 2003 R2) to use Com Interops.
I tried to be descriptive in the comments but feel free to ask questions about it.
'Returns Byte(), UTF-8 bytes of unicode string
Function Utf8Bytes(text)
With Server.CreateObject("System.Text.UTF8Encoding")
Utf8Bytes = .GetBytes_4(text)
End With
End Function
'Returns String, sequential hexadecimal digits per byte
'data As Byte()
Function BinToHex(data)
With Server.CreateObject("MSXML2.DomDocument").CreateElement("b64")
.dataType = "bin.hex"
.nodeTypedValue = data
BinToHex = .text
End With
End Function
'Returns Byte(), a keyed hash generated using SHA256 method
'data As String, key As Byte()
Function HashHmacSha256(data, key)
With Server.CreateObject("System.Security.Cryptography.HMACSHA256")
.Key = key
HashHmacSha256 = .ComputeHash_2(UTF8Bytes(data))
End With
End Function
'Returns Byte(), of a packed hexadecimal string
'instead of PHP's pack('H*'
Function HexToBin(data)
With Server.CreateObject("MSXML2.DomDocument").CreateElement("b64")
.dataType = "bin.hex"
.text = data
HexToBin = .nodeTypedValue
End With
End Function
packed_secret = HexToBin("1234567890ABCDEF")
message = "stackoverflow"
binary_hash = HashHmacSha256(message, packed_secret)
string_hash = BinToHex(binary_hash)
Response.Write string_hash
This is my VB6 Code
Private Function Encryp_HMACSHA1(pData As String, pSecretKey As String) As String
Dim encoder As Object
Dim crypto As Object
Dim i As Integer
Dim bSecretKey() As Byte
Dim bData() As Byte
Dim bEncrypted() As Byte
Set encoder = CreateObject("System.Text.UTF8Encoding")
Set crypto = CreateObject("System.Security.Cryptography.HMACSHA1")
bData = encoder.Getbytes_4(pData)
bSecretKey = encoder.Getbytes_4(pSecretKey)
crypto.Key = bSecretKey
bEncrypted = crypto.ComputeHash_2(bData)
Set encoder = Nothing
Set crypto = Nothing
Dim objXML As MSXML2.DOMDocument
Dim objNode As MSXML2.IXMLDOMElement
Set objXML = New MSXML2.DOMDocument
Set objNode = objXML.createElement("b64")
objNode.dataType = "bin.base64"
objNode.nodeTypedValue = bEncrypted
EncodeBase64 = objNode.Text
Encryp_HMACSHA1 = EncodeBase64
Set objNode = Nothing
Set objXML = Nothing
End Function
Public Function Pack(strlength As String) As String
Dim Temp As String
Dim MyString As String
Dim i As Integer
MyString = ""
For i = 1 To Len(strlength) Step 2
Temp = Mid(strlength, i, 2)
MyString = MyString & Chr(CLng("&H" & Temp))
Next
Pack = MyString
End Function
Private Sub Command1_Click()
Dim pKey As String
pKey = Pack("1989151498577ad12a9f8adf157f5abf")
Text1.Text = Encryp_HMACSHA1("test", pKey)
End Sub
result for vb is : 03AM+k4B3mPEZlkCatDvdiHOuuc=
This is my php code
$key = "1989151498577ad12a9f8adf157f5abf";
$decodeKey = pack("H*",$key);
$data = "test";
$hash = hash_hmac("SHA1", $data, $decodeKey, TRUE);
$signature = base64_encode($hash);
echo $signature;
result for the php is : 4QXpNBD/cv0sLIfFIsFGe5D57gI=
Please help in solving the equation.
And There is another problem, If we encrypt the data without pack method both are the outputs are same, but if we does with pack it shows different results.
Your VB6 Pack function is:
converting two hex digits at a time to bytes, then
converting those values to characters with ANSI-to-Unicode translation.
Then your Encryp_HMACSHA1:
takes such String values and converts them into Byte arrays using conversion to UTF-8, and
feeds that into crypto.Key to munch on.
Playing fast and loose using Strings in this manner has corrupted your key value.
I was apply to reproduce the incorrect signature result by taking known-working VB6 code and altering it to perform the same distortion.
I'm not sure why you are using this great big heavy .Net inter-clop approach to doing part of the job and then taking another really heavy run through an MSXML DOM just for Base64 encoding. Wow, do you have enough RAM for this to even run?
I used the HS1.cls from the attachment (HS1 Demo 1-1.zip) at:
[VB6] HMAC-SHA-256, HMAC-SHA-1 Using Crypto API #35
Then all that was required was:
Private Function HMACSHA1(ByVal Data As String, ByVal Key As String) As String
With New HS1
.InitHmac .Decode(Key, edfHexRaw)
HMACSHA1 = .Encode(.HMACSHA1(.ToUTF8(Data)), edfBase64, efNoFolding)
End With
End Function
Where Data is VB6/Windows "Unicode" text (UCS-2/UTF-16LE) and Key is a "Unicode" string of hexadecimal text. E.g.:
txtSignature.Text = HMACSHA1("test", "1989151498577ad12a9f8adf157f5abf")
Sure enough, it produces:
4QXpNBD/cv0sLIfFIsFGe5D57gI=
This is also far lighter weight than using (a.) the .Net CLR and Framework libraries plus "interop" and (b.) MSXML as super-fat wrappers around simple API calls.
But you could keep all of that overhead if you really want to as long as you correct your "String of hex digits to Key" parsing logic.
If "1989151498577ad12a9f8adf157f5abf" is supposed to be the key in hexadecimal the php code is correct.
Verify if Encryp_HMACSHA1 expects the key to be data or a hexadecimal string.
Verify if the keys after conversion to data are the same by displaying them in hex
I found a lot of solutions that explain how to look at C# versus PHP, but none specific to VB. I did find one helpful hint about PHP padding with zeroes, but that didn't solve the problem as I matched that in VB and it didn't help. Anyway I am familiar with VB and we have another developer familiar with PHP and we are trying to make our functions match so that tripleDES encryption spits out the same value in both. We are integrating with a third party application, and I know the VB code is spitting out the correct value but PHP is not. I have both VB and PHP code listed below, would anyone out there be familiar enough with both to have any idea why the PHP code isn't returning the correct value? I know the value that is being returned from PHP is the correct length, but there is something off and it's not matching. Please help.
VB:
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs)
Dim dataToHash As String
Dim encryptedText As String = ""
dataToHash = "hereismystring"
Dim buffer As Byte() = Encryption(dataToHash, "abcd1234")
encryptedText = Convert.ToBase64String(buffer)
lblToken.Text = encryptedText.ToString()
End Sub
Public Shared Function Encryption(ByVal PlainText As String, ByVal key As String) As Byte()
Dim des As TripleDES = CreateDES(key)
Dim ct As ICryptoTransform = des.CreateEncryptor()
Dim input As Byte() = Encoding.Unicode.GetBytes(PlainText)
Return ct.TransformFinalBlock(input, 0, input.Length)
End Function
Private Shared Function CreateDES(ByVal key As String) As TripleDES
Dim md5 As MD5 = New MD5CryptoServiceProvider()
Dim des As TripleDES = New TripleDESCryptoServiceProvider()
des.Key = md5.ComputeHash(Encoding.Unicode.GetBytes(key))
des.IV = New Byte(des.BlockSize / 8 - 1) {}
des.Padding = PaddingMode.Zeros
Return des
End Function
PHP:
$start = "hereismystring";
$cipher = MCRYPT_TRIPLEDES;
$mode = MCRYPT_MODE_CBC;
$rawKey = "abcd1234";
$ssoKey = md5($key_encoded,true);
$key_size = strlen($ssoKey);
$iv_size = mcrypt_get_iv_size(MCRYPT_TRIPLEDES, MCRYPT_MODE_CBC);
$ssoIV = mcrypt_create_iv($iv_size, MCRYPT_RAND);
$user_str = mb_convert_encoding($start,"UTF-16LE");
$key_blocksize = mcrypt_get_block_size($cipher,$mode);
$key_padding_size = $key_blocksize - (strlen($user_str) % $key_blocksize);
$user_str .= str_repeat(chr($key_padding_size), $key_padding_size);
$key_iv = mcrypt_create_iv(mcrypt_get_iv_size($cipher,$mode),"");
$key_triple = substr($key_encoded,0,mcrypt_get_key_size($cipher,$mode));
$key_encoded_text = mcrypt_encrypt($cipher,$key_triple,$user_str,$mode,$key_iv);
$final = base64_encode($key2_encoded_text);
echo "<p>" . $final </p>";
?>
Thanks,
Joe
I am trying to find a way in PHP that can encrypt a string in hex using DES algorithm. The result I need should be exactly like this page.
All PHP codes that I tried gave different results than what I got in that page.
I tried this code for example:
<?php
function Encrypt($data, $key)
{
$encData = mcrypt_encrypt('tripledes', $key, $data, 'ecb');
return $encData;
}
echo strtoupper(bin2hex(Encrypt("12341234", "1100000120140129")));
?>
The result was: 0D54E1C0B08DCB90. While in this link, the result is: 4DC7D8B78F0F33A3.
Note that 31313030303030313230313430313239 is 1100000120140129 in hex
and 3132333431323334 is 12341234 in hex.
This code did the trick for me:
$keyA = "11000001";
$keyB = "20140129";
$data = "12341234";
$TMP = mcrypt_encrypt('tripledes', $keyA, $data, 'ecb');
$TMP = mcrypt_decrypt('tripledes', $keyB, $TMP, 'ecb');
echo strtoupper(bin2hex(mcrypt_encrypt('tripledes', $keyA, $TMP, 'ecb')));
I used two-key triple DES method to generate the exact result in this DES calculator website.
Encrypt the data using the first half of the key (most left 8 digits)
Decrypt the ciphertext using the second half of the key (most right 8 digits)
Re-encrypt the ciphertext using the first half of the key again
Thanks to #Duncan for the useful help.
This problem seems to be caused by the way PHP reads keys and data when you supply them as strings. Solve this problem by using code such as the following:
$key = pack('H*', "0123456789abcdef"); // this correctly maps hex to bytes
$data = pack('H*', "0123456789abcdef");
echo bin2hex(mcrypt_encrypt(MCRYPT_DES, $key, $data, MCRYPT_MODE_ECB));
This outputs 56cc09e7cfdc4cef which matches the DES calculator (proof).
For those interested, I also used the following Java code to deduce what was going on. This prints the same result as the PHP:
SecretKey key = new SecretKeySpec(new byte[8], "DES");
Cipher cipher = Cipher.getInstance("DES/ECB/NoPadding");
cipher.init(Cipher.ENCRYPT_MODE, key);
System.out.println(DatatypeConverter.printHexBinary(cipher
.doFinal(new byte[8])));
I'm trying to do a simple task. Encypt a value in PHP and Decrypt it in my VB.net app.
I figure I'd use tripleDES or Rijdael 128 or 256
I though this should be simple. Can anyone point me in the right direction?
Thank you
I also looked long and hard for solutions to this problem. Here is a complete set of code for both php and vb.net that will do what you are looking for. Should be pretty easy to translate to C# as well.
########################################
# BEGIN PHP CODE
########################################
<?php
ini_set('display_errors', 1);
error_reporting(E_ALL);
// I blantantly stole, tweaked and happily used this code from:
// Lord of Ports http://www.experts-exchange.com/M_1736399.html
$ky = 'lkirwf897+22#bbtrm8814z5qq=498j5'; // 32 * 8 = 256 bit key
$iv = '741952hheeyy66#cs!9hjv887mxx7#8y'; // 32 * 8 = 256 bit iv
$text = "Here is my data to encrypt!!!";
$from_vb = "QBlgcQ2+v3wd8RLjhtu07ZBd8aQWjPMfTc/73TPzlyA="; // enter value from vb.net app here to test
$etext = encryptRJ256($ky, $iv, $text);
$dtext = decryptRJ256($ky, $iv, $etext);
$vtext = decryptRJ256($ky, $iv, $from_vb);
echo "<HR>orignal string: $text";
echo "<HR>encrypted in php: $etext";
echo "<HR>decrypted in php: $dtext";
echo "<HR>encrypted in vb: $from_vb";
echo "<HR>from vb decrypted in php: $vtext";
echo "<HR>If you like it say thanks! richard dot varno at gmail dot com";
exit;
function decryptRJ256($key,$iv,$string_to_decrypt)
{
$string_to_decrypt = base64_decode($string_to_decrypt);
$rtn = mcrypt_decrypt(MCRYPT_RIJNDAEL_256, $key, $string_to_decrypt, MCRYPT_MODE_CBC, $iv);
$rtn = rtrim($rtn, "\0\4");
return($rtn);
}
function encryptRJ256($key,$iv,$string_to_encrypt)
{
$rtn = mcrypt_encrypt(MCRYPT_RIJNDAEL_256, $key, $string_to_encrypt, MCRYPT_MODE_CBC, $iv);
$rtn = base64_encode($rtn);
return($rtn);
}
?>
########################################
# END PHP CODE
########################################
########################################
# BEGIN VB.NET CODE (console app)
########################################
Imports System
Imports System.Text
Imports System.Security.Cryptography
Imports System.IO
Module Module1
' I blantantly stole, tweaked and happily used this code from:
' Lord of Ports http://www.experts-exchange.com/M_1736399.html
Sub Main()
'Shared 256 bit Key and IV here
Dim sKy As String = "lkirwf897+22#bbtrm8814z5qq=498j5" '32 chr shared ascii string (32 * 8 = 256 bit)
Dim sIV As String = "741952hheeyy66#cs!9hjv887mxx7#8y" '32 chr shared ascii string (32 * 8 = 256 bit)
Dim sTextVal As String = "Here is my data to encrypt!!!"
Dim eText As String
Dim dText As String
eText = EncryptRJ256(sKy, sIV, sTextVal)
dText = DecryptRJ256(sKy, sIV, eText)
Console.WriteLine("key: " & sKy)
Console.WriteLine()
Console.WriteLine(" iv: " & sIV)
Console.WriteLine("txt: " & sTextVal)
Console.WriteLine("encrypted: " & eText)
Console.WriteLine("decrypted: " & dText)
Console.WriteLine("If you like it say thanks! richard dot varno at gmail dot com")
Console.WriteLine("press any key to exit")
Console.ReadKey(True)
End Sub
Public Function DecryptRJ256(ByVal prm_key As String, ByVal prm_iv As String, ByVal prm_text_to_decrypt As String)
Dim sEncryptedString As String = prm_text_to_decrypt
Dim myRijndael As New RijndaelManaged
myRijndael.Padding = PaddingMode.Zeros
myRijndael.Mode = CipherMode.CBC
myRijndael.KeySize = 256
myRijndael.BlockSize = 256
Dim key() As Byte
Dim IV() As Byte
key = System.Text.Encoding.ASCII.GetBytes(prm_key)
IV = System.Text.Encoding.ASCII.GetBytes(prm_iv)
Dim decryptor As ICryptoTransform = myRijndael.CreateDecryptor(key, IV)
Dim sEncrypted As Byte() = Convert.FromBase64String(sEncryptedString)
Dim fromEncrypt() As Byte = New Byte(sEncrypted.Length) {}
Dim msDecrypt As New MemoryStream(sEncrypted)
Dim csDecrypt As New CryptoStream(msDecrypt, decryptor, CryptoStreamMode.Read)
csDecrypt.Read(fromEncrypt, 0, fromEncrypt.Length)
Return (System.Text.Encoding.ASCII.GetString(fromEncrypt))
End Function
Public Function EncryptRJ256(ByVal prm_key As String, ByVal prm_iv As String, ByVal prm_text_to_encrypt As String)
Dim sToEncrypt As String = prm_text_to_encrypt
Dim myRijndael As New RijndaelManaged
myRijndael.Padding = PaddingMode.Zeros
myRijndael.Mode = CipherMode.CBC
myRijndael.KeySize = 256
myRijndael.BlockSize = 256
Dim encrypted() As Byte
Dim toEncrypt() As Byte
Dim key() As Byte
Dim IV() As Byte
key = System.Text.Encoding.ASCII.GetBytes(prm_key)
IV = System.Text.Encoding.ASCII.GetBytes(prm_iv)
Dim encryptor As ICryptoTransform = myRijndael.CreateEncryptor(key, IV)
Dim msEncrypt As New MemoryStream()
Dim csEncrypt As New CryptoStream(msEncrypt, encryptor, CryptoStreamMode.Write)
toEncrypt = System.Text.Encoding.ASCII.GetBytes(sToEncrypt)
csEncrypt.Write(toEncrypt, 0, toEncrypt.Length)
csEncrypt.FlushFinalBlock()
encrypted = msEncrypt.ToArray()
Return (Convert.ToBase64String(encrypted))
End Function
End Module
########################################
# END VB.NET CODE
########################################
We have some ciphers working between C# on .NET and PHP. I am not familiar with VB.net. I assume it uses the same crypto library System.Security.Cryptography.
On PHP side, we switched from mcrypt to OpenSSL because some modes and paddings are not supported by mcrypt.
As long as you use same algorithm (DES, AES etc), same mode (CBC, ECB etc), same padding (PKCS1, PKCS5), the cipher should work on both platforms.
Example of encryption using AES-128 on PHP side using mcrypt,
$iv_size = mcrypt_get_iv_size(MCRYPT_RIJNDAEL_128, MCRYPT_MODE_CBC);
$iv = mcrypt_create_iv($iv_size, MCRYPT_RAND);
$blockSize = mcrypt_get_block_size(MCRYPT_RIJNDAEL_128);
$data = $this->paddingAlgorithm->padData($data, $blockSize);
return $iv . mcrypt_encrypt($this->MCRYPT_DES, $keyBytes, $data, MCRYPT_MODE_CBC, $iv);
Please note that we use PKCS7 padding but mcrypt doesn't support it so we have to write the padding algorithm. We also prepend the IV (Initial Vector) to the cipher text. You might store it somewhere else but you need that to decrypt.
Here is the corresponding C# code to setup the cipher to decrypt,
// create the underlying symmetric algorithm with the given name
algorithm = (SymmetricAlgorithm)CryptoConfig.CreateFromName("RIJNDAEL");
// set cipher mode
algorithm.Mode = CipherMode.CBC;
// set padding mode
algorithm.Padding = PaddingMode.PKCS7;
For PHP you should look at the mcrypt extension, which should support all of the ciphers you specified
Disclaimer: I've never actually used the Crytography classes in .NET.
To do Rijndael decryption in .NET, you're probably looking for the System.Security.Cryptography.RijndaelManaged class.
That page also has some examples of how to use it, although you may also need an instance of RSACryptoServiceProvider... I'm not sure.