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 9182615
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T18:36:06+00:00 2026-06-17T18:36:06+00:00

Took the vectors from this site http://www.inconteam.com/software-development/41-encryption/55-aes-test-vectors#aes-ecb-128 In javascript (sjcl) have the same result

  • 0

Took the vectors from this site http://www.inconteam.com/software-development/41-encryption/55-aes-test-vectors#aes-ecb-128

In javascript (sjcl) have the same result

var key = [0x2b7e1516,0x28aed2a6,0xabf71588,0x09cf4f3c];
var test  = [0x6bc1bee2,0x2e409f96,0xe93d7e11,0x7393172a];
aes = new sjcl.cipher.aes(key);
r = aes.encrypt(test);
console.log(r);

But I can not reach it in the C#

    [TestMethod]
    public void EncryptIntsToInts()
    {
        Int32[] key = { unchecked((Int32)0x2b7e1516), 0x28aed2a6, unchecked((Int32)0xabf71588), 0x09cf4f3c };
        Int32[] test = { 0x6bc1bee2,0x2e409f96,unchecked((Int32)0xe93d7e11),0x7393172a };
        Int32[] answer = { 0x3ad77bb4, 0x0d7a3660, unchecked((Int32)0xa89ecaf3), 0x2466ef97 };

        var r = AES.EncryptIntsToInts(test, key.ToByteArray());

        Assert.IsTrue(r.SequenceEqual(answer));
    }


    static byte[] zeroIV = new byte[] { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };

    public static Int32[] EncryptIntsToInts(Int32[] input, byte[] key)
    {
        // Check arguments.
        if (input == null || input.Length <= 0)
            throw new ArgumentNullException("input");
        if (key == null || key.Length <= 0)
            throw new ArgumentNullException("key");

        // Declare the RijndaelManaged object
        // used to encrypt the data.
        RijndaelManaged aesAlg = null;
        byte[] bResult;
        try
        {
            aesAlg = new RijndaelManaged
                         {
                             Key = key,
                             Mode = CipherMode.ECB,
                             Padding = PaddingMode.None,
                             KeySize = 128,
                             BlockSize = 128,
                             IV = zeroIV
                         };
            ICryptoTransform encryptor = aesAlg.CreateEncryptor();

            byte[] bInput = new byte[input.Length * sizeof(int)];
            Buffer.BlockCopy(input, 0, bInput, 0, bInput.Length);

            bResult = encryptor.TransformFinalBlock(bInput, 0, input.Length);
        }
        finally
        {
            if (aesAlg != null)
                aesAlg.Clear();
        }

        int[] iResult = new int[bResult.Length / sizeof(int)];
        Buffer.BlockCopy(bResult, 0, iResult, 0, bResult.Length);
        return iResult;
    }

What is my error?

========================================================

Start edit

New code in which right order of the bytes, but it does not work

    [TestMethod]
    public void EncryptIntsToInts()
    {
        byte[] key =     "2b7e151628aed2a6abf7158809cf4f3c".HEX2Bytes();
        byte[] test =    "6bc1bee22e409f96e93d7e117393172a".HEX2Bytes();
        byte[] answer =  "3ad77bb40d7a3660a89ecaf32466ef97".HEX2Bytes();

        RijndaelManaged aesAlg = new RijndaelManaged
        {
            Key = key,
            Mode = CipherMode.ECB,
            Padding = PaddingMode.PKCS7,
            KeySize = 128,
            BlockSize = 128,
            IV = zeroIV
        };
        ICryptoTransform encryptor = aesAlg.CreateEncryptor();

        var r = encryptor.TransformFinalBlock(test, 0, test.Length);

        Assert.IsTrue(r.SequenceEqual(answer));
    }

    public static byte[] HEX2Bytes(this string hex)
    {
        if (hex.Length%2 != 0)
        {
            throw new ArgumentException(String.Format(CultureInfo.InvariantCulture,
                                                      "The binary key cannot have an odd number of digits: {0}", hex));
        }

        byte[] HexAsBytes = new byte[hex.Length/2];
        for (int index = 0; index < HexAsBytes.Length; index++)
        {
            string byteValue = hex.Substring(index*2, 2);
            HexAsBytes[index] = byte.Parse(byteValue, NumberStyles.HexNumber, CultureInfo.InvariantCulture);
        }

        return HexAsBytes;
    }

    static byte[] zeroIV = new byte[] { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
  • 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-17T18:36:07+00:00Added an answer on June 17, 2026 at 6:36 pm

    You use 32 bit integers to define the key. When you transform them to bytes, you use native endianness, which typically is little endian. So your key is 16157e2b a6... and not 2b7e1516 28....

    I wouldn’t use ints to represent a key in the first place. But if you really want to, write a big endian conversion function.

    I also strongly recommend against ECB mode. You could use CBC together with HMAC (in an encrypt then mac construction), or use a third party lib to implement GCM.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I took the example code from the Kendo UI demos at http://demos.kendoui.com/web/grid/remote-data.html , binding
I took an example from https://www.kernel.org/doc/man-pages/online/pages/man3/pthread_create.3.html made it run infinitely(with small sleep so CPU
I took this code from Facebook's documentation to get me started in learning how
I took the rendered page from the SWT Browser and exported it to an
I took over an old HTML based site with all hard coded links, no
I took a look at this answer and it goes in part to solving
It took me awhile to figure out this error and was wondering why the
I took some code from some questions here in SO as well as some
While playing with VS11 beta I noticed something weird: this code couts f took
I took the following code example from a Struts2 textbook, the purpose of the

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.