Asp.Net中使用的加密是什么?
What is the encryption used in Asp.Net?
美好的一天!
我是 Asp.Net 的新人,我想重新创建 Asp.Net 的注册。我试图找到 Asp.Net 默认使用的加密代码和插入命令。顾名思义,我想知道使用的加密方式是什么?它是散列或 md5 还是其他方法,我在哪里可以找到代码?
通常,注册后端代码有这个命令
var manager = Context.GetOwinContext().GetUserManager<ApplicationUserManager>();
var signInManager = Context.GetOwinContext().Get<ApplicationSignInManager>();
var user = new ApplicationUser() { UserName = Username.Text, Email = Username.Text };
IdentityResult result = manager.Create(user, Password.Text);
我知道 signInManager 不是命令,我尝试检查 IdentityResult
但一无所获。
提前致谢。
加密密码
string Password = EncryptString(Password.Text);
Here I'm Encrypting the Password Using UTF8... So You can Store the
Encrypted Password In Database...
public static string EncryptString(string str)
{
return Encrypt(str, "!#$a54?3");
}
private static string Encrypt(string stringToEncrypt, string sEncryptionKey)
{
byte[] key = { };
byte[] IV = { 10, 20, 30, 40, 50, 60, 70, 80 };
byte[] inputByteArray; //Convert.ToByte(stringToEncrypt.Length)
try
{
key = Encoding.UTF8.GetBytes(sEncryptionKey.Substring(0, 8));
DESCryptoServiceProvider des = new DESCryptoServiceProvider();
inputByteArray = Encoding.UTF8.GetBytes(stringToEncrypt);
MemoryStream ms = new MemoryStream();
CryptoStream cs = new CryptoStream(ms, des.CreateEncryptor(key, IV), CryptoStreamMode.Write);
cs.Write(inputByteArray, 0, inputByteArray.Length);
cs.FlushFinalBlock();
return Convert.ToBase64String(ms.ToArray());
}
catch (System.Exception ex)
{
throw ex;
}
}
解密密码
Same Way you can Decrypt the Password
public static string DecryptString(string str)
{
return Decrypt(str, "!#$a54?3");
}
private static string Decrypt(string stringToDecrypt, string sEncryptionKey)
{
byte[] key = { };
byte[] IV = { 10, 20, 30, 40, 50, 60, 70, 80 }; //try {&H12, &H34, &H56, &H78, &H90, &HAB, &HCD, &HEF}
byte[] inputByteArray = new byte[stringToDecrypt.Length];
try
{
key = Encoding.UTF8.GetBytes(sEncryptionKey.Substring(0, 8));
DESCryptoServiceProvider des = new DESCryptoServiceProvider();
inputByteArray = Convert.FromBase64String(stringToDecrypt.Replace(" ", "+"));
MemoryStream ms = new MemoryStream();
CryptoStream cs = new CryptoStream(ms, des.CreateDecryptor(key, IV), CryptoStreamMode.Write);
cs.Write(inputByteArray, 0, inputByteArray.Length);
cs.FlushFinalBlock();
Encoding encoding = Encoding.UTF8;
return encoding.GetString(ms.ToArray());
}
catch (System.Exception ex)
{
throw ex;
}
}
注意:- 使用相同的密钥加密和解密密码...我在这里使用 !#$a54?3
美好的一天!
我是 Asp.Net 的新人,我想重新创建 Asp.Net 的注册。我试图找到 Asp.Net 默认使用的加密代码和插入命令。顾名思义,我想知道使用的加密方式是什么?它是散列或 md5 还是其他方法,我在哪里可以找到代码?
通常,注册后端代码有这个命令
var manager = Context.GetOwinContext().GetUserManager<ApplicationUserManager>();
var signInManager = Context.GetOwinContext().Get<ApplicationSignInManager>();
var user = new ApplicationUser() { UserName = Username.Text, Email = Username.Text };
IdentityResult result = manager.Create(user, Password.Text);
我知道 signInManager 不是命令,我尝试检查 IdentityResult
但一无所获。
提前致谢。
加密密码
string Password = EncryptString(Password.Text);
Here I'm Encrypting the Password Using UTF8... So You can Store the Encrypted Password In Database...
public static string EncryptString(string str)
{
return Encrypt(str, "!#$a54?3");
}
private static string Encrypt(string stringToEncrypt, string sEncryptionKey)
{
byte[] key = { };
byte[] IV = { 10, 20, 30, 40, 50, 60, 70, 80 };
byte[] inputByteArray; //Convert.ToByte(stringToEncrypt.Length)
try
{
key = Encoding.UTF8.GetBytes(sEncryptionKey.Substring(0, 8));
DESCryptoServiceProvider des = new DESCryptoServiceProvider();
inputByteArray = Encoding.UTF8.GetBytes(stringToEncrypt);
MemoryStream ms = new MemoryStream();
CryptoStream cs = new CryptoStream(ms, des.CreateEncryptor(key, IV), CryptoStreamMode.Write);
cs.Write(inputByteArray, 0, inputByteArray.Length);
cs.FlushFinalBlock();
return Convert.ToBase64String(ms.ToArray());
}
catch (System.Exception ex)
{
throw ex;
}
}
解密密码
Same Way you can Decrypt the Password
public static string DecryptString(string str)
{
return Decrypt(str, "!#$a54?3");
}
private static string Decrypt(string stringToDecrypt, string sEncryptionKey)
{
byte[] key = { };
byte[] IV = { 10, 20, 30, 40, 50, 60, 70, 80 }; //try {&H12, &H34, &H56, &H78, &H90, &HAB, &HCD, &HEF}
byte[] inputByteArray = new byte[stringToDecrypt.Length];
try
{
key = Encoding.UTF8.GetBytes(sEncryptionKey.Substring(0, 8));
DESCryptoServiceProvider des = new DESCryptoServiceProvider();
inputByteArray = Convert.FromBase64String(stringToDecrypt.Replace(" ", "+"));
MemoryStream ms = new MemoryStream();
CryptoStream cs = new CryptoStream(ms, des.CreateDecryptor(key, IV), CryptoStreamMode.Write);
cs.Write(inputByteArray, 0, inputByteArray.Length);
cs.FlushFinalBlock();
Encoding encoding = Encoding.UTF8;
return encoding.GetString(ms.ToArray());
}
catch (System.Exception ex)
{
throw ex;
}
}
注意:- 使用相同的密钥加密和解密密码...我在这里使用 !#$a54?3