Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4612800
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T01:27:14+00:00 2026-05-22T01:27:14+00:00

I know how to convert from a string to byte[] in C#. In this

  • 0

I know how to convert from a string to byte[] in C#. In this particular case, I’m working with the string representation of an HMAC-SHA256 key. Let’s say the string representation of this key I get from an OpenID OP is:

"81FNybKWfcM539vVGtJrXRmoVMxNmZHY3OgUro8+pZ8="

I convert it to byte[] like this:

byte[] myByteArr = Encoding.UTF8.GetBytes("81FNybKWfcM539vVGtJrXRmoVMxNmZHY3OgUro8+pZ8=");

The problem I have with that is that it seems to be losing the original data. If I take the byte array from the previous step and convert it back to a string, it’s different from the original string.

string check = Convert.ToBase64String(myByteArr);

check ends up being:

"ODFGTnliS1dmY001Mzl2Vkd0SnJYUm1vVk14Tm1aSFkzT2dVcm84K3BaOD0="

which is obviously not the same as the original string representation I started with.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-22T01:27:15+00:00Added an answer on May 22, 2026 at 1:27 am

    With crypto keys, always use Convert.FromBase64String and Convert.ToBase64String. That way you’ll be doing it the standard way and will not lose bytes due to encoding problems. Base 64 string may not be space efficient but it is the preferred method for storage and transport of keys in many schemes.

    Here is a quick verification:

    byte[] myByteArr = Convert.FromBase64String("81FNybKWfcM539vVGtJrXRmoVMxNmZHY3OgUro8+pZ8=");
    string check = Convert.ToBase64String(myByteArr);
    Console.WriteLine(check);
    // Writes: 81FNybKWfcM539vVGtJrXRmoVMxNmZHY3OgUro8+pZ8=
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I get a String data from Cursor, but I don't know how to convert
I have a String created from a byte[] array, using UTF-8 encoding. However, it
How do I convert from 8 bit byte to 7 bit byte (Base 256
How can I convert a string of bytes into an int in python? Say
I want to convert a string into a byte array. (Yes) I have seen
I receive the following string from one website via mechanize: 'We\x92ve' I know that
What is the fastest way you know to convert a floating-point number to an
When you search in Google 100F to C how does it know to convert
Does anyone know how to convert long to short pathnames in .net 3.5 without
I already know how to convert the non-utf8-encoded content of a file line by

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.