Click here to Skip to main content
15,886,578 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hello,
I want to encrypt "Hello world" after click on encrypt Button string should be written in different encrypted format.

For example:
Actual string        out put (i want)  

Hello world          rdIaJwuMRHupXSA7NDjf+Q==         
Hello world          +I3MFzYshgcXg0OCKI6WJQ==       
Hello world          3fYzgRUkKdc6A2hNnKM8lA==
Posted
Updated 30-Mar-15 1:15am
v3
Comments
Kornfeld Eliyahu Peter 30-Mar-15 2:39am    
The samples you are presenting here look like Base64 encoding - there is no encryption here...
prashant9393 30-Mar-15 2:44am    
i want same string input but return diffrent Out put
Kornfeld Eliyahu Peter 30-Mar-15 2:46am    
And what will make the difference?
Do you want a true encryption (one way or two way?) or only encoding?
prashant9393 30-Mar-15 2:53am    
one way encryption. i want implement product key. if i use this product key so never use on next installation
Kornfeld Eliyahu Peter 30-Mar-15 2:58am    
So why encryption - use some random generated value like GUID for every installation...

Its encrypt function

C#
public static string Base64Encode(string sData)
  {
      try
      {
          byte[] toEncodeAsBytes = System.Text.Encoding.Unicode.GetBytes(sData);
          string returnValue = Convert.ToBase64String(toEncodeAsBytes);

          return returnValue;
      }
      catch (Exception ex)
      {
          throw new Exception("Error in base64Encode" + ex.Message);
      }
  }
 
Share this answer
 
Comments
George Jonsson 30-Mar-15 3:14am    
This solution will give the same result every time.
Member 11478643 30-Mar-15 3:21am    
string newencrypt=RandomString(15).ToString() + returnValue;

add this .
George Jonsson 30-Mar-15 3:32am    
Why would I add anything?
It is your solution, I just pointed out that the OP wanted different results for each request.
And this is not really encryption, right.
prashant9393 30-Mar-15 4:56am    
i use this line code but RandomString is show the error please send the code
prashant9393 30-Mar-15 4:51am    
i use byte[] toEncodeAsBytes = System.Text.Encoding.Unicode.GetBytes("prashant");
string returnValue = Convert.ToBase64String(toEncodeAsBytes);

but it's Return Same Result Always I want diffrent Result
private const string Chars =abcdefgijkmnopqrstwxyz23456789abcdefgijkmnopqrstwxyz;
private readonly Random _rng = new Random();

public static string Base64Encode(string sData)
  {
      try
      {
          byte[] toEncodeAsBytes = System.Text.Encoding.Unicode.GetBytes(sData);
          string returnValue = Convert.ToBase64String(toEncodeAsBytes);
             string newencryptName = RandomString(15).ToString() + returnValue;
          return newencryptName;
      }
      catch (Exception ex)
      {
          throw new Exception("Error in base64Encode" + ex.Message);
      }
  }

private string RandomString(int size)
{
var buffer = new char[size];

for (var i = 0; i < size; i++)
{
buffer[i] = Chars[_rng.Next(Chars.Length)];
}
return new string(buffer);
}
 
Share this answer
 
v3
Comments
prashant9393 31-Mar-15 1:50am    
this code always return Same Value
prashant = UAByAGEAcwBoAGEAbgB0AA==
Repeat Prashant
prashant = UAByAGEAcwBoAGEAbgB0AA==

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900