-1

Builtin function for Javascript equivalent for this code? i tried using CryptoJS but the bytes are not matching. Any builtin method available

byte[] tempBytes = (new UnicodeEncoding()).GetBytes("TestWord");

I have used CryptoJS but still it doesn't provide same bytes

<script src="https://crypto-js.googlecode.com/svn/tags/3.1.2/build/rollups/sha1.js"></script>
<script src="https://crypto-js.googlecode.com/svn/tags/3.1.2/build/components/core-min.js"></script>
<script src="https://crypto-js.googlecode.com/svn/tags/3.1.2/build/components/enc-utf16-min.js"></script>
<script src="https://crypto-js.googlecode.com/svn/tags/3.1.2/build/components/enc-base64-min.js"></script>
<script>
    var words=CryptoJS.enc.Utf16.parse('TestWord');
   console.log(words); 

</script>
Sam Joe
  • 1
  • 7
  • 1
    possible duplicate of [Unicode value \uXXXX to Character in Javascript](http://stackoverflow.com/questions/3835317/unicode-value-uxxxx-to-character-in-javascript) – mjw Aug 26 '15 at 20:57
  • No its not duplicate i tried using this library still i can't get the same bytes please help – Sam Joe Aug 26 '15 at 22:56

2 Answers2

1

I have used CryptoJS before CryptoJS CryptoJS.enc.Utf16.parse('TestWord'); returns object which has an array of words. If you convert the words to byte using

CryptoJS.util.wordsToBytes(words.words) it will return the same bytes

i have made JSFiddle Here working as well Link here

sumeet kumar
  • 2,628
  • 1
  • 16
  • 24
-1

I use a class Crypto in c# and my code is:

byte[] tempByte = Encoding.Unicode.GetBytes(myTextToEncryp);

Try this.

Nicolas C
  • 225
  • 2
  • 8