1

Can anyone please suggest the C# equivalent of Hex.decodeHex() which is in Java.

Below the example in java:

Key = "7777777777777777777777777777777777777777777777777777777777777777";
byte[] KeyInBytes = Hex.decodeHex(Key.toCharArray());  

I am looking for the c# equivalent of this

Any help here is highly appreciated.

Marco
  • 55,302
  • 13
  • 128
  • 150
Sammy
  • 57
  • 1
  • 5
  • How about explain what that does, in words and stuff :)) – TheGeneral Oct 14 '21 at 09:26
  • https://stackoverflow.com/questions/16999604/convert-string-to-hex-string-in-c-sharp Please refer to this link. Might be exactly what you need –  Oct 14 '21 at 09:27
  • @TheGeneral decodeHex() Converts an array of characters representing hexadecimal values into an array of bytes of those same values. – Sammy Oct 14 '21 at 09:50

2 Answers2

5

In .NET 5 and later you can use Convert.FromHexString().

Martin Costello
  • 8,236
  • 5
  • 56
  • 64
0

Convert string to hex-string in C#, I think that you are trying to do something like this. I think it is Encoding.Default.GetBytes(Key); as the previous link shows

Iria
  • 79
  • 6
  • This is not correct. `Encoding.Default.GetBytes(Key)` does something completely different – canton7 Oct 14 '21 at 09:33
  • As it’s currently written, your answer is unclear. Please [edit] to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Oct 14 '21 at 09:47