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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T11:22:39+00:00 2026-05-30T11:22:39+00:00

currently im using System.Security.Cryptography and this is my code for it: private static SymmetricAlgorithm

  • 0

currently im using System.Security.Cryptography and this is my code for it:

    private static SymmetricAlgorithm createCryptoServiceProvider(string key, string IV)
    {
        byte[] password;

        using (MD5 md5 = MD5.Create())
            password = md5.ComputeHash(Encoding.UTF8.GetBytes(key));
        var crypt = new TripleDESCryptoServiceProvider();
        byte[] iv = Encoding.UTF8.GetBytes(IV);
        crypt.IV = iv;
        crypt.Key = password;
        return crypt;
    }
    public static byte[] Serialize(object obj, string key, string key2)
    {
        var provider = createCryptoServiceProvider(key, key2);
        using (MemoryStream memory = new MemoryStream())
        {
            using (CryptoStream stream = new CryptoStream(memory, provider.CreateEncryptor(), CryptoStreamMode.Write))
            {
                BinaryFormatter formatter = new BinaryFormatter();
                formatter.Serialize(stream, obj);
            }
            return memory.ToArray();
        }

    }
    public static object Deserialize(byte[] inBytes, string key, string key2)
    {
        var provider = createCryptoServiceProvider(key, key2);

        using(MemoryStream memory = new MemoryStream(inBytes))
        {
            using (CryptoStream stream = new CryptoStream(memory, provider.CreateDecryptor(), CryptoStreamMode.Read))
            {
                BinaryFormatter formatter = new BinaryFormatter();
                return formatter.Deserialize(stream);
            }
        }
    }

i use this when getting ready to send data over a socket, I create a object that will have the key in a private field and also keep the key so it knows the key, when the object is received on the other client then it uses a function inside the object that was sent that uses that private string key, key2; and encrypts the message into bytes and sets the keys to “” and then it sends the object back holding the bytes. so now only the original sender can decrypt it. Is this a good way to do this or is there a better way?

  • 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-30T11:22:41+00:00Added an answer on May 30, 2026 at 11:22 am

    Don’t try to do the encryption yourself.

    http://msdn.microsoft.com/en-us/library/system.net.security.sslstream.aspx

    The example code uses TcpClient, but it should work with any stream IO, so direct sockets should be fine also.

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

Sidebar

Related Questions

I maintain the build system at my company, which is currently using CVS. This
Currently when I make a signature using java.security.signature, it passes back a string. I
Currently using System.Web.UI.WebControls.FileUpload wrapped in our own control. We have licenses for Telerik. I
I am currently using Subversion as my Source Control system, mainly because I found
We are currently using Fitnesse for sub system testing. [All our applications are in
My company is currently using Sage MAS as their ERP system. While integrating our
I am currently using asp.NET MVC to build a Content Management System parts of
I currently have a class file with the following enumeration: using System; namespace Helper
I'm trying to implement a mailing list system for my application. I'm currently using
I am trying to subclass the currently focused window on a Windows system using

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.