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

  • Home
  • SEARCH
  • 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 9064411
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T16:14:42+00:00 2026-06-16T16:14:42+00:00

I have a 128-bit key that I want to store in a database. My

  • 0

I have a 128-bit key that I want to store in a database. My code creates the key as byte[16] and the datatype in the database is varbinary(16).

When I try to retrieve the byte array again from the db, I don’t get the original values.

Here is my code:

byte[] test =  new byte[16]{0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15};

SqlCommand myInsertCmd = new SqlCommand("INSERT INTO Test(test) VALUES(@Param)", myConnection);       
SqlParameter param = myInsertCmd.Parameters.Add("@Param", SqlDbType.VarBinary, 16);
param.Value = test;

myInsertCmd.ExecuteNonQuery();

SqlDataAdapter myAdapter1 = new SqlDataAdapter("Select test from Test;", myConnection);
DataTable dt = new DataTable();
myAdapter1.Fill(dt);

foreach (DataRow row in dt.Rows)
{
    char[] charArray = row["test"].ToString().ToCharArray();
}

For charArray, I get 0x0053, 0x0079,0x0073,0x0074, etc and also, the charArray is only 13 bytes long. What am I doing wrong?

  • 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-06-16T16:14:43+00:00Added an answer on June 16, 2026 at 4:14 pm

    row["Test"] contains byte[], so row["Test"].ToString() returns default ToString of byte[] type, which is "System.Byte[]". After which you convert System.Byte[] and get that result

    foreach (DataRow row in dt.Rows)
    {
        byte[] byteArray = (byte[])row["test"];
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a 128 bit encryption key that I would like to break up
I have a 128-byte (1024-bit) modulus (in a byte array format) and my exponent
I need to store a large (128-bit) PK. Each int will have some corresponding
I have created a SecretkeySpec object wich contains a 128 bit key. I would
I have a function that operates on 128-bit blocks of data from an arbitrary-length
I have the following C code: typedef void (*mycallback) (char buf[128]); void take_callback(mycallback cb)
I have a code that goes something like: $cipher_alg = MCRYPT_RIJNDAEL_128; $decrypted_string = mcrypt_decrypt($cipher_alg,
I need a CORE that will perform AES-128 Encryption/Decryption. I have searched online but
I want to use PBKDF2 with some cryptographic hash function to generate 128-bit AES
I have a text file that I have to sign with RSA private key

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.