Copy link to clipboard
Copied
How can i Use it in Action script . my VB code is following
Encoding.UTF8.GetBytes("String") and System.Text.Encoding.Default.GetBytes("char array")
Thank You . !
Udit Bhardwaj
1 Correct answer
I fond the way to convert it accordingly
Encoding.UTF8.GetBytes("String") it is in ActionScript :
YourByteArray.writeMultiByte("String", "iso-8859-1");
And
System.Text.Encoding.Default.GetBytes("char array")
YourByteArray.writeMultiByte("String","String");
Thank you for your suggestions moccamaximum
Thank You !
Udit Bhardwaj
Copy link to clipboard
Copied
Copy link to clipboard
Copied
Thanks but there is some error . i want to hash my salted password . I am providing my VB code here Please Help me sir!
Public Sub GetHashString(ByVal Data As String, ByRef Hash As String, ByVal Salt As String)
'see GetHashAndSaltString for more details
Dim HashOut() As Byte
HashOut = ComputeHash(Encoding.UTF8.GetBytes(Data), System.Text.Encoding.Default.GetBytes(Salt.ToString.ToCharArray))
Hash = Convert.ToBase64String(HashOut)
End Sub
and
definition Of compute hash is
Private Function ComputeHash(ByVal Data() As Byte, ByVal Salt() As Byte) As Byte()
' Allocate memory to store both the Data and Salt together
Dim DataAndSalt() As Byte = New Byte(((Data.Length + SaltLength)) - 1) {}
' Copy both the data and salt into the new array
Array.Copy(Data, DataAndSalt, Data.Length)
Array.Copy(Salt, 0, DataAndSalt, Data.Length, SaltLength)
' Calculate the hash
' Compute hash value of our plain text with appended salt.
Return HashProvider.ComputeHash(DataAndSalt)
End Function
i want to do exactly through ActionScript
Thanks a Ton in advance
Copy link to clipboard
Copied
It`s not much of a use to "translate" your code example to AS3 because it is not complete.
A general rule of thumb for key differneces between AS3 and VB
1.AS3 uses brackets instead of End commands
2. construcrtor arguments are writen like so:
_data:ByteArray,_salt:ByteArray
3.return values are obligatory for functions
4.visibiliy keywords (private, public, protected) are only valid within packages
function computeHash(_data:ByteArray,_salt:ByteArray):ByteArray{
...
}
some links that could be helpful for you:
Base64Encoder - Adobe ActionScript® 3 (AS3 Flex) API Reference
Adobe AIR 1.5 * Example: Generating and using an encryption key
Copy link to clipboard
Copied
I have made functions according to this a few days back, but there are several errors in my code . tried to fix them one by one . but not able to find the function which can do what i am doing in the VB . That is why i was trying to convert it . Trying Back to make those mistakes fix again.
Thanks Btw
Copy link to clipboard
Copied
I fond the way to convert it accordingly
Encoding.UTF8.GetBytes("String") it is in ActionScript :
YourByteArray.writeMultiByte("String", "iso-8859-1");
And
System.Text.Encoding.Default.GetBytes("char array")
YourByteArray.writeMultiByte("String","String");
Thank you for your suggestions moccamaximum
Thank You !
Udit Bhardwaj
Copy link to clipboard
Copied
That isn't right, Bear in mind that your code may be working right now, but it may break on some use cases. ISO-8859-1 is not UTF-8 at all, you should use YourByteArray.writeMultiByte("String", "utf-8");
About YourByteArray.writeMultiByte("String","String"); it works because String is not a valid charset, so it uses the default code page, which is what you want, but be really careful with using it, if the machines writing and reading the data are different, the default code page could be different, and the encoding/decoding part of the string will work, but some later data processing or displaying may break because some bytes equal to different chars in different code pages. I've worked on projects where developers were not aware of this, or either didn't care/think it was going to be a problem in the future, and at the end the code had either to be changed or force the end users to modify their system's default code page (which brought other problems or complaints).
Copy link to clipboard
Copied
YourByteArray.writeMultiByte("String", "utf-8");
Thanks for telling me a few important things , i will make it Correct. In my hashing process it is working fine . ok i will try with what you have suggested Me ..
Thanks A ton @Neverbirth
Udit Bhardwaj
Copy link to clipboard
Copied
YourByteArray.writeMultiByte("String", "utf-8");
Thanks for telling me a few important things , i will make it Correct. In my hashing process it is working fine . ok i will try with what you have suggested Me ..
Thanks A ton @Neverbirth
Udit Bhardwaj

