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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T06:31:11+00:00 2026-06-04T06:31:11+00:00

I need to encrypt a text string in a .net application using a known

  • 0

I need to encrypt a text string in a .net application using a known text key, and then decrypt it in Ruby using the same known key…however I’m having trouble making this happen. I think it has to do with string encoding issues. .Net to Ruby RC4 examples have proven to be elusive.

I’m receiving and invalid decryption on the Ruby side. The encryption/decryption works fine on the .net implementation. But when I copy the encrypted value over to the Ruby implementation and use the same key, I don’t get my original value.

Below is my .net RC4 implementation (this does not require the highest level of security, but some is nice) 🙂

On the ruby side I’m using ruby-rc4 https://github.com/caiges/Ruby-RC4

       public string keytext = "thisismykey";
    public Form1()
    {
        InitializeComponent();
    }
    public void RC4(ref Byte[] bytes, Byte[] key)
    {

        Byte[] s = new Byte[256];
        Byte[] k = new Byte[256];
        Byte temp;
        int i, j;

        for (i = 0; i < 256; i++)
        {
            s[i] = (Byte)i;
            k[i] = key[i % key.GetLength(0)];
        }

        j = 0;
        for (i = 0; i < 256; i++)
        {
            j = (j + s[i] + k[i]) % 256;
            temp = s[i];
            s[i] = s[j];
            s[j] = temp;
        }

        i = j = 0;
        for (int x = 0; x < bytes.GetLength(0); x++)
        {
            i = (i + 1) % 256;
            j = (j + s[i]) % 256;
            temp = s[i];
            s[i] = s[j];
            s[j] = temp;
            int t = (s[i] + s[j]) % 256;
            bytes[x] ^= s[t];
        }
    }
    static byte[] GetBytes(string str)
    {
        Byte[] bytes = new byte[str.Length * sizeof(char)];
        System.Buffer.BlockCopy(str.ToCharArray(), 0, bytes, 0, bytes.Length);
        return bytes;
    }
    static string GetString(byte[] bytes)
    {
        char[] chars = new char[bytes.Length / sizeof(char)];
        System.Buffer.BlockCopy(bytes, 0, chars, 0, bytes.Length);
        return new string(chars);
    }
    private void button1_Click(object sender, EventArgs e)
    {
        Byte[] content = Encoding.ASCII.GetBytes(textBox1.Text);
        RC4(ref content, Encoding.ASCII.GetBytes(keytext));
        textBox2.Text = Encoding.ASCII.GetString(content);
        RC4(ref content, Encoding.ASCII.GetBytes(keytext));
        label1.Text = Encoding.ASCII.GetString(content);
    }
  • 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-04T06:31:12+00:00Added an answer on June 4, 2026 at 6:31 am

    The problem is likely occurring because ASCII encoding is 7-bit and has trouble recreating characters for values above 127. Try encoding with UTF-8 or convert the byte array to a Base64 string.

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

Sidebar

Related Questions

I need to encrypt some text with RSA, and then recover it later using
I need to encrypt / decrypt passwords for a new application. The spec requires
in function need key to encrypt string without mcrypt libraly in php function encrypt($str,
I need help converting this into PHP: Public Function Encrypt(ByVal text As String) As
i need to decrypt some cypherd text (aes 128 ctr) programming in C using
I have a .NET application. I need to store a text value encrypted in
I need to encrypt a string (from a text area) that will also be
I need to obfuscate or encrypt some plain text data in my php 5.2
I need to encrypt & decrypt data with both Java (on Android) and SJCL
I need two methods one to encrypt and one to decrypt an xml file

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.