| |

VerySource

 Forgot password?
 Register
Search
View: 785|Reply: 6

Problems saving password to INI file encryption

[Copy link]

1

Threads

1

Posts

2.00

Credits

Newbie

Rank: 1

Credits
2.00

 China

Post time: 2020-1-26 01:40:01
| Show all posts |Read mode
A user login interface. After saving the password, the password is encrypted and saved to the ini file.
Then read the decryption to verify
Is there any better way to use this kind of encryption?
Ha ha
Just touched on program design, everyone guides ~~
Reply

Use magic Report

0

Threads

2

Posts

3.00

Credits

Newbie

Rank: 1

Credits
3.00

 China

Post time: 2020-2-16 10:00:01
| Show all posts
MD5 will do
Also. There are also encryption algorithms in .NET
Reply

Use magic Report

0

Threads

9

Posts

8.00

Credits

Newbie

Rank: 1

Credits
8.00

 China

Post time: 2020-2-17 09:15:02
| Show all posts
MD5 cannot be decrypted (not to mention theoretical things). It can be implemented with DES, RSA and other classes. There are examples in msdn.
Reply

Use magic Report

1

Threads

7

Posts

8.00

Credits

Newbie

Rank: 1

Credits
8.00

 Invalid IP Address

Post time: 2020-2-23 09:45:01
| Show all posts
MD5 cannot and does not need to be decrypted. It is better and more secure to compare the encrypted cipher text directly.
Reply

Use magic Report

0

Threads

23

Posts

20.00

Credits

Newbie

Rank: 1

Credits
20.00

 China

Post time: 2020-3-1 19:30:02
| Show all posts
MD5 is irreversible, but directly compare the encrypted ciphertext
Reply

Use magic Report

0

Threads

16

Posts

13.00

Credits

Newbie

Rank: 1

Credits
13.00

 China

Post time: 2020-3-6 11:00:01
| Show all posts
It is recommended to use DES or RSA, this is really encryption.

MD5 is a hash value, not really encrypted, just a hash

Posting a DES method gives you:

// Initialize the DES encryption key and a random, 8-bit initialization vector (IV)
private byte [] key_8 = {0x01, 0x23, 0x45, 0x67, 0x89, 0xab, 0xcd, 0xef};
private byte [] IV_8 = {0x12, 0x34, 0x56, 0x78, 0x90, 0xab, 0xcd, 0xef};


/// <summary>
/// DES decryption string
/// </ summary>
/// <param name = "decryptString"> string to be decrypted </ param>
/// <param name = "rgbKey"> Decryption key, requires 8 bits, same as encryption key </ param>
/// <param name = "rgbIV"> key vector </ param>
/// <returns> Successful decryption returns the decrypted string, failure to return to the source string </ returns>
private string DES_Decrypt (string decryptString, byte [] rgbKey, byte [] rgbIV)
{
try
{
byte [] inputByteArray = Convert.FromBase64String (decryptString);
DESCryptoServiceProvider DCSP = new DESCryptoServiceProvider ();
MemoryStream mStream = new MemoryStream ();
CryptoStream cStream = new CryptoStream (mStream, DCSP.CreateDecryptor (rgbKey, rgbIV), CryptoStreamMode.Write);
cStream.Write (inputByteArray, 0, inputByteArray.Length);
cStream.FlushFinalBlock ();
return Encoding.UTF8.GetString (mStream.ToArray ());
}
catch
{
return decryptString;
}
}

/// <summary>
/// TripleDES encrypted string
/// </ summary>
/// <param name = "encryptString"> string to be encrypted </ param>
/// <param name = "rgbKey"> key </ param>
/// <param name = "rgbIV"> key vector </ param>
/// <returns> The encrypted string is returned after the encryption is successful, or the source string is returned if the encryption fails </ returns>
private string TripleDES_Encrypt (string encryptString, byte [] rgbKey, byte [] rgbIV)
{
try
{
byte [] inputByteArray = Encoding.UTF8.GetBytes (encryptString);
TripleDESCryptoServiceProvider dCSP = new TripleDESCryptoServiceProvider ();
MemoryStream mStream = new MemoryStream ();
CryptoStream cStream = new CryptoStream (mStream, dCSP.CreateEncryptor (rgbKey, rgbIV), CryptoStreamMode.Write);
cStream.Write (inputByteArray, 0, inputByteArray.Length);
cStream.FlushFinalBlock ();
return Convert.ToBase64String (mStream.ToArray ());
}
catch
{
return encryptString;
}
}
Reply

Use magic Report

0

Threads

16

Posts

13.00

Credits

Newbie

Rank: 1

Credits
13.00

 China

Post time: 2020-3-6 13:30:01
| Show all posts
Sorry, ls posted it wrong, it became a triple DES
Should be this:

// Initialize the DES encryption key and a random, 8-bit initialization vector (IV)
private byte [] key_8 = {0x01, 0x23, 0x45, 0x67, 0x89, 0xab, 0xcd, 0xef};
private byte [] IV_8 = {0x12, 0x34, 0x56, 0x78, 0x90, 0xab, 0xcd, 0xef};


/// <summary>
/// DES encrypted string
/// </ summary>
/// <param name = "encryptString"> string to be encrypted </ param>
/// <param name = "rgbKey"> encryption key, requires 8 bits </ param>
/// <param name = "rgbIV"> key vector </ param>
/// <returns> The encrypted string is returned after the encryption is successful, and the source string is returned if the encryption fails </ returns>
private string DES_Encrypt (string encryptString, byte [] rgbKey, byte [] rgbIV)
{
try
{
byte [] inputByteArray = Encoding.UTF8.GetBytes (encryptString);
DESCryptoServiceProvider dCSP = new DESCryptoServiceProvider ();
MemoryStream mStream = new MemoryStream ();
CryptoStream cStream = new CryptoStream (mStream, dCSP.CreateEncryptor (rgbKey, rgbIV), CryptoStreamMode.Write);
cStream.Write (inputByteArray, 0, inputByteArray.Length);
cStream.FlushFinalBlock ();
return Convert.ToBase64String (mStream.ToArray ());
}
catch
{
return encryptString;
}
}

/// <summary>
/// DES decryption string
/// </ summary>
/// <param name = "decryptString"> string to be decrypted </ param>
/// <param name = "rgbKey"> Decryption key, requires 8 bits, same as encryption key </ param>
/// <param name = "rgbIV"> key vector </ param>
/// <returns> Successful decryption returns the decrypted string, failure to return to the source string </ returns>
private string DES_Decrypt (string decryptString, byte [] rgbKey, byte [] rgbIV)
{
try
{
byte [] inputByteArray = Convert.FromBase64String (decryptString);
DESCryptoServiceProvider DCSP = new DESCryptoServiceProvider ();
MemoryStream mStream = new MemoryStream ();
CryptoStream cStream = new CryptoStream (mStream, DCSP.CreateDecryptor (rgbKey, rgbIV), CryptoStreamMode.Write);
cStream.Write (inputByteArray, 0, inputByteArray.Length);
cStream.FlushFinalBlock ();
return Encoding.UTF8.GetString (mStream.ToArray ());
}
catch
{
return decryptString;
}
}
Reply

Use magic Report

You have to log in before you can reply Login | Register

Points Rules

Contact us|Archive|Mobile|CopyRight © 2008-2023|verysource.com ( 京ICP备17048824号-1 )

Quick Reply To Top Return to the list