Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

how can i use VB's Encoding.UTF8.GetBytes() and System.Text.Encoding.Default.GetBytes() in actionscript Can Somebody help me ??

Community Beginner ,
May 23, 2014 May 23, 2014

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

TOPICS
ActionScript
3.5K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Community Beginner , May 29, 2014 May 29, 2014

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

Translate
Guru ,
May 23, 2014 May 23, 2014
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
May 23, 2014 May 23, 2014

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

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guru ,
May 23, 2014 May 23, 2014

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

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
May 23, 2014 May 23, 2014

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

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
May 29, 2014 May 29, 2014

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

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
May 30, 2014 May 30, 2014

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

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
May 30, 2014 May 30, 2014
LATEST

  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

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
May 30, 2014 May 30, 2014

  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

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines