//[ScriptMethod(ResponseFormat = System.Web.Script.Services.ResponseFormat.Xml)] public STReturn Login_UserName(string UserName, string LoginPwd) { // 先清除已登录数据 Session.Clear(); STReturn stReturn = new STReturn(); Apq.Web.SessionState.HttpSessionState ApqSession = new Apq.Web.SessionState.HttpSessionState(Session); if (LoginPwd.Length < 1) { stReturn.NReturn = -1; stReturn.ExMsg = "密码不允许为空"; return(stReturn); } System.Security.Cryptography.SHA512 SHA512 = System.Security.Cryptography.SHA512.Create(); byte[] binLoginPwd = SHA512.ComputeHash(System.Text.Encoding.Unicode.GetBytes(LoginPwd)); stReturn = DBLogin(UserName, binLoginPwd); // Session操作 if (stReturn.NReturn > 0) { ApqSession.User = stReturn.FNReturn as DataTable; } ApqSession.LoginTime = DateTime.Now; return(stReturn); }
/// <summary> /// Hash SHA-512 de um Conteúdo em Array de Bytes /// </summary> /// <param name="input"></param> /// <returns>Retorna o Hash em string Hexadecimal</returns> public static string SHA512(byte[] input) { using System.Security.Cryptography.SHA512 hash = System.Security.Cryptography.SHA512.Create(); return(BitConverter.ToString(hash.ComputeHash(input)) .Replace("-", "").ToLower()); }
//[ScriptMethod(ResponseFormat = System.Web.Script.Services.ResponseFormat.Xml, XmlSerializeString = true)] public Apq.STReturn UserEditLoginPwd(string LoginPwd_C, string LoginPwd) { Apq.STReturn stReturn = new Apq.STReturn(); DinnerSession ApqSession = new DinnerSession(Session); if (!CheckLoginPage.CheckLogin(ref stReturn, ApqSession)) { return(stReturn); } // 检测旧密码 System.Security.Cryptography.SHA512 SHA512 = System.Security.Cryptography.SHA512.Create(); byte[] binLoginPwd_C = SHA512.ComputeHash(System.Text.Encoding.Unicode.GetBytes(LoginPwd_C)); string SqlLoginPwd_C = Apq.Data.SqlClient.Common.ConvertToSqlON(binLoginPwd_C); string SqlLoginPwd_DB = Apq.Data.SqlClient.Common.ConvertToSqlON(ApqSession.ApqLogin.LoginPwd); if (SqlLoginPwd_C != SqlLoginPwd_DB) { stReturn.NReturn = -1; stReturn.ExMsg = "原密码输入错误"; return(stReturn); } byte[] binLoginPwd = SHA512.ComputeHash(System.Text.Encoding.Unicode.GetBytes(LoginPwd)); DbConnection SqlConn = null; using (SqlConn = Apq.DBC.Common.CreateDBConnection("Dinner", ref SqlConn)) { Apq.Data.Common.DbConnectionHelper dbch = new Apq.Data.Common.DbConnectionHelper(SqlConn); DbCommand sc = SqlConn.CreateCommand(); sc.CommandText = "dbo.Dinner_User_UpdateLoginPwd"; sc.CommandType = CommandType.StoredProcedure; Apq.Data.Common.DbCommandHelper dch = new Apq.Data.Common.DbCommandHelper(sc); dch.AddParameter("rtn", 0, DbType.Int32); dch.AddParameter("ExMsg", stReturn.ExMsg, DbType.String, -1); dch.AddParameter("LoginID", ApqSession.ApqLogin.LoginID); dch.AddParameter("LoginPwd", binLoginPwd); sc.Parameters["rtn"].Direction = ParameterDirection.ReturnValue; sc.Parameters["ExMsg"].Direction = ParameterDirection.InputOutput; SqlConn.Open(); sc.ExecuteNonQuery(); stReturn.NReturn = System.Convert.ToInt32(sc.Parameters["rtn"].Value); stReturn.ExMsg = sc.Parameters["ExMsg"].Value.ToString(); sc.Dispose(); SqlConn.Close(); } // 更新Session中的密码信息 ApqSession.ApqLogin.LoginPwd = binLoginPwd; // 返回客户端 stReturn.FNReturn = Apq.Data.SqlClient.Common.ConvertToSqlON(binLoginPwd); return(stReturn); }
static void Main(string[] args) { Console.Write("Password: "******"{0} ", asciiCode[i]); //} System.Security.Cryptography.SHA512 converter = System.Security.Cryptography.SHA512.Create(); //encrypt = 1 way //encode = 2 ways Console.WriteLine("Without salt"); string encryptedValue = Convert.ToBase64String(converter.ComputeHash(asciiCode)); Console.WriteLine("Encrypted Value:\n{0}", encryptedValue); Console.WriteLine("\n\n"); Console.WriteLine("With salt"); asciiCode = Encoding.Unicode.GetBytes(password + "1"); encryptedValue = Convert.ToBase64String(converter.ComputeHash(asciiCode)); Console.WriteLine("Encrypted Value:\n{0}", encryptedValue); Console.ReadKey(); }
public static string GetSHA512(this byte[] input, int offset, int count) { using (System.Security.Cryptography.SHA512 sha512 = System.Security.Cryptography.SHA512.Create()) { return(Convert.ToHexString(sha512.ComputeHash(input, offset, count)).ToLower()); } }
/// <summary> /// Gets the sh a512 hash as hexadecimal string. /// </summary> /// <param name="data">The data.</param> /// <returns></returns> public static string GetSHA512HashAsHexString(byte[] data) { System.Security.Cryptography.SHA512 sha512Implementation = System.Security.Cryptography.SHA512.Create(); var hashData = sha512Implementation.ComputeHash(data); return(GeneralConverters.ByteArrayToHexString(hashData)); }
//[ScriptMethod(ResponseFormat = System.Web.Script.Services.ResponseFormat.Xml)] public Apq.STReturn Login_LoginName(string LoginName, string LoginPwd) { // 先清除已登录数据 Session.Clear(); Apq.STReturn stReturn = new Apq.STReturn(); DinnerSession ApqSession = new DinnerSession(Session); if (LoginPwd.Length < 1) { stReturn.NReturn = -1; stReturn.ExMsg = "密码不允许为空"; return(stReturn); } System.Security.Cryptography.SHA512 SHA512 = System.Security.Cryptography.SHA512.Create(); byte[] binLoginPwd = SHA512.ComputeHash(System.Text.Encoding.Unicode.GetBytes(LoginPwd)); stReturn = DBLogin(LoginName, binLoginPwd); // Session操作 if (stReturn.NReturn > 0) { // 登录成功 DataTable dt = stReturn.FNReturn as DataTable; Login_Session(ApqSession, dt); } return(stReturn); }
public async override Task <byte[]> HashAsync(string value) { using (System.Security.Cryptography.SHA512 hasher = System.Security.Cryptography.SHA512.Create()) { // await is necessary here to avoid disposing of the hasher object // ReSharper disable once AccessToDisposedClosure return(await Task.Run(() => hasher.ComputeHash(Encoding.UTF8.GetBytes(value))).ConfigureAwait(false)); } }
public BaoMat(string plaintext) { ptext = plaintext; shaM = new System.Security.Cryptography.SHA512Managed(); byte[] input = Encoding.UTF8.GetBytes(ptext); byte[] result = shaM.ComputeHash(input); ctext = System.Convert.ToBase64String(result); }
public static void Test() { SaltyRandomGenerator srg = new SaltyRandomGenerator(); srg.getsalt += srg_getsalt; BitCollector collector = new BitCollector(512); int bits; int n; for (bits = 1; bits < 28; bits++) { srg.Reset(); collector.Clear(); for (n = 0; n < (512 - bits); n += bits) { int value = srg.GetEntropy(bits, false); collector.AddBits((uint)value, bits); } { int final_value = srg.GetEntropy(512 - n, false); collector.AddBits((uint)final_value, 512 - n); } byte[] one = srg.entropy; byte[] two = collector.buffer; for (n = 0; n < 512 / 8; n++) { if (one[n] != two[n]) { Console.WriteLine("Byte " + n + " differed " + one[n].ToString("x") + " " + two[n].ToString("x")); } } } for (bits = 1; bits < 28; bits++) { srg.Reset(); collector.Clear(); for (n = 0; n < (512 - bits); n += bits) { int value = srg.GetEntropy(bits, true); collector.AddBits((uint)value, bits); //Console.WriteLine( "data is : " + value ); } { int final_value = srg.GetEntropy(512 - n, false); collector.AddBits((uint)final_value, 512 - n); } byte[] one = srg.entropy; byte[] two = collector.buffer; for (n = 0; n < 512 / 8; n++) { if (one[n] != two[n]) { Console.WriteLine("Byte " + n + " differed " + one[n].ToString("x") + " " + two[n].ToString("x")); } } } }
public static string Sha512(string s) { byte[] bytes = System.Text.Encoding.ASCII.GetBytes(s); System.Security.Cryptography.SHA512 sha = System.Security.Cryptography.SHA512.Create(); byte[] hash = sha.ComputeHash(bytes); string result = System.Text.Encoding.ASCII.GetString(hash); return(result); }
public static string GetCrypt(string text) { string hash = ""; System.Security.Cryptography.SHA512 alg = System.Security.Cryptography.SHA512.Create(); byte[] result = alg.ComputeHash(Encoding.UTF8.GetBytes(text)); hash = Encoding.UTF8.GetString(result); return(hash); }
public bool Decode(byte[] data, string password) { var msEncoded = new MemoryStream(data); byte[] buffer = new byte[4]; msEncoded.Read(buffer, 0, 4); int encodedBytes = BitConverter.ToInt32(buffer, 0); buffer = new byte[encodedBytes]; msEncoded.Read(buffer, 0, buffer.Length); byte[] decodedBytes = EncryptionManager.DecryptData(buffer, password); msEncoded.Read(buffer, 0, 4); int hashByteLength = BitConverter.ToInt32(buffer, 0); if (hashByteLength > 512) { return(false); } byte[] hashBytesFromData = new byte[hashByteLength]; msEncoded.Read(hashBytesFromData, 0, hashBytesFromData.Length); byte[] hashBytesFromDecodedDataBytes = SHA512.Create().ComputeHash(decodedBytes, 0, decodedBytes.Length); bool hashCompareResult = GeneralConverters.ByteArrayToBase64(hashBytesFromData) == GeneralConverters.ByteArrayToBase64(hashBytesFromDecodedDataBytes); if (!hashCompareResult) { return(false); } var msDecoded = new MemoryStream(decodedBytes); buffer = new byte[4]; msDecoded.Read(buffer, 0, buffer.Length); int leftPaddingLength = BitConverter.ToInt32(buffer, 0); msDecoded.Read(buffer, 0, buffer.Length); int rightPaddingLength = BitConverter.ToInt32(buffer, 0); msDecoded.Read(buffer, 0, buffer.Length); int totalLength = BitConverter.ToInt32(buffer, 0); byte[] decodedDataBlock = new byte[totalLength]; msDecoded.Read(decodedDataBlock, 0, decodedDataBlock.Length); byte[] sharedSecretBytes = new byte[totalLength - leftPaddingLength - rightPaddingLength]; Buffer.BlockCopy(decodedDataBlock, leftPaddingLength, sharedSecretBytes, 0, sharedSecretBytes.Length); SharedSecret = GeneralConverters.GetStringFromByteArray(sharedSecretBytes); return(true); }
/// <summary> /// Get the hash for the SHA-512 algorithim. /// </summary> /// <param name="data"> /// </param> /// <returns> /// </returns> public byte[] GetHash(byte[] data) { byte[] hash = null; using (System.Security.Cryptography.SHA512 crypto = System.Security.Cryptography.SHA512.Create()) { hash = crypto.ComputeHash(data); } return(hash); }
public string Generate(string text) { using (System.Security.Cryptography.SHA512 sha512 = System.Security.Cryptography.SHA512.Create()) { byte[] hashBytes = sha512.ComputeHash(Encoding.ASCII.GetBytes(text)); StringBuilder sb = new StringBuilder(); for (int i = 0; i < hashBytes.Length; i++) { sb.Append(hashBytes[i].ToString("X2")); } return(sb.ToString()); } }
public override string ComputeHashFromFile(string filePath) { try { System.Security.Cryptography.SHA512 sha512 = System.Security.Cryptography.SHA512.Create(); FileStream fs = File.OpenRead(filePath); byte[] outputBytes = sha512.ComputeHash(fs); return(BitConverter.ToString(outputBytes).Replace("-", "").ToLower()); } catch (Exception e) { return("\nERROR: " + e.Message); } }
public override string ComputeHashFromText(string text) { try { System.Security.Cryptography.SHA512 sha512 = System.Security.Cryptography.SHA512.Create(); byte[] inputBytes = Encoding.UTF8.GetBytes(text); byte[] outputBytes = sha512.ComputeHash(inputBytes); return(BitConverter.ToString(outputBytes).Replace("-", "").ToLower()); } catch (Exception e) { return("\nERROR: " + e.Message); } }
public string HashPassword(string password) { if (String.IsNullOrEmpty(password)) { throw new ArgumentNullException("password"); } // Keep your Password Salt in User/Environment specific config settings! string Salt = AppConfig.GetValue("PasswordSalt"); System.Security.Cryptography.SHA512 hasher = System.Security.Cryptography.SHA512.Create(); byte[] pwdHashed = hasher.ComputeHash( hasher.ComputeHash( hasher.ComputeHash(Encoding.UTF8.GetBytes(Salt + password)))); return(pwdHashed.ToHexString()); }
public static string SHA512(string toHash) { // Use input string to calculate MD5 hash using (System.Security.Cryptography.SHA512 sha512 = System.Security.Cryptography.SHA512.Create()) { byte[] inputBytes = System.Text.Encoding.ASCII.GetBytes(toHash); byte[] hashBytes = sha512.ComputeHash(inputBytes); // Convert the byte array to hexadecimal string StringBuilder sb = new StringBuilder(); for (int i = 0; i < hashBytes.Length; i++) { sb.Append(hashBytes[i].ToString("X2")); } return(sb.ToString()); } }
int my_get_mask(byte[] data, int bits) { uint result; int offset = 0; // how many bits were used of the first byte int first_used_bits = (bits_used & 7); // how many bits are availablt in first byte (to align to byte read) int first_bits = 8 - first_used_bits; if (first_used_bits > 0) { if (bits <= first_bits) { result = (((uint)data[bits_used / 8] >> first_used_bits) & my_mask_mask(bits)); bits_used += bits; return((int)result); } else { result = (uint)data[bits_used / 8] >> first_used_bits; bits -= first_bits; bits_used += first_bits; offset = first_bits; } } else { result = 0; } while (bits >= 8) { result |= (uint)data[(bits_used / 8)] << offset; //result |= data[b++]; bits -= 8; offset += 8; bits_used += 8; } if (bits > 0) { result |= (data[bits_used / 8] & my_mask_mask(bits)) << offset; bits_used += bits; } return((int)result); }
public static bool _Create_System_String( ) { //Parameters System.String hashName = null; //ReturnType/Value System.Security.Cryptography.SHA512 returnVal_Real = null; System.Security.Cryptography.SHA512 returnVal_Intercepted = null; //Exception Exception exception_Real = null; Exception exception_Intercepted = null; InterceptionMaintenance.disableInterception( ); try { returnValue_Real = System.Security.Cryptography.SHA512.Create(hashName); } catch (Exception e) { exception_Real = e; } InterceptionMaintenance.enableInterception( ); try { returnValue_Intercepted = System.Security.Cryptography.SHA512.Create(hashName); } catch (Exception e) { exception_Intercepted = e; } Return((exception_Real.Messsage == exception_Intercepted.Message) && (returnValue_Real == returnValue_Intercepted)); }
/// <summary> /// Codifica una cadena (texto plano) usando el algoritmo SHA512. /// </summary> /// <see cref="http://msdn.microsoft.com/en-us/library/system.security.cryptography.sha512.aspx"/> /// <param name="plain">La cadena, en texto plano, que se desea codificar.</param> /// <returns>Retorna un valor de tipo String del valor codificado en formato hexadecimal.</returns> static string GetCryptedString(string plain) { string result = string.Empty; try { plain = plain.Trim(); using (System.Security.Cryptography.SHA512 sha512 = System.Security.Cryptography.SHA512.Create()) { byte[] data = sha512.ComputeHash(Encoding.UTF8.GetBytes(plain)); for (int i = 0; i < data.Length; i++) { result += data[i].ToString("x2"); } } } catch { result = string.Empty; } return(result); }
public byte[] Encode(string password) { var secureRandom = new SecureRandomGenerator(); var msBlock = new MemoryStream(); var msContent = new MemoryStream(); int leftPaddingLength = secureRandom.GetRandomInt(64, 512); int rightPaddingLength = secureRandom.GetRandomInt(64, 512); byte[] sharedSecretBytes = GeneralConverters.GetByteArrayFromString(SharedSecret); byte[] buffer = BitConverter.GetBytes(leftPaddingLength); msBlock.Write(buffer, 0, buffer.Length); buffer = BitConverter.GetBytes(rightPaddingLength); msBlock.Write(buffer, 0, buffer.Length); buffer = BitConverter.GetBytes(leftPaddingLength + rightPaddingLength + sharedSecretBytes.Length); msBlock.Write(buffer, 0, buffer.Length); msBlock.Write(secureRandom.GetRandomData(leftPaddingLength), 0, leftPaddingLength); msBlock.Write(sharedSecretBytes, 0, sharedSecretBytes.Length); msBlock.Write(secureRandom.GetRandomData(rightPaddingLength), 0, rightPaddingLength); byte[] encodeBytes = msBlock.ToArray(); encodeBytes = EncryptionManager.EncryptData(encodeBytes, password); byte[] hashBytes = SHA512.Create().ComputeHash(encodeBytes, 0, encodeBytes.Length); buffer = BitConverter.GetBytes(encodeBytes.Length); msContent.Write(buffer, 0, buffer.Length); msBlock.WriteTo(msContent); buffer = BitConverter.GetBytes(hashBytes.Length); msContent.Write(buffer, 0, buffer.Length); msContent.Write(hashBytes, 0, hashBytes.Length); return(msContent.ToArray()); }
public int GetEntropy(int bits, bool signed) { int tmp; int partial_tmp = 0; // redundant init; this does not have to be initialized. int partial_bits = 0; if (bits > (bits_avail - bits_used)) { if (bits_avail - bits_used > 0) { partial_bits = bits_avail - bits_used; partial_tmp = my_get_mask(entropy, partial_bits); bits -= partial_bits; } GetBits(); } { tmp = my_get_mask(entropy, bits); if (partial_bits > 0) { tmp = partial_tmp | (tmp << partial_bits); bits += partial_bits; // restore bit counter for signed computation } if (signed) { if ((tmp & (1 << (bits - 1))) != 0) { uint negone = ~(uint)0; negone <<= bits; return((int)((uint)tmp | negone)); } } } return(tmp); }
public static void Test() { SaltyRandomGenerator srg = new SaltyRandomGenerator(); srg.getsalt += srg_getsalt; BitCollector collector = new BitCollector( 512 ); int bits; int n; for( bits = 1; bits < 28; bits++ ) { srg.Reset(); collector.Clear(); for( n = 0; n < ( 512 - bits ); n += bits ) { int value = srg.GetEntropy( bits, false ); collector.AddBits( (uint)value, bits ); } { int final_value = srg.GetEntropy( 512 - n, false ); collector.AddBits( (uint)final_value, 512 - n ); } byte[] one = srg.entropy; byte[] two = collector.buffer; for( n = 0; n < 512 / 8; n++ ) { if( one[n] != two[n] ) Console.WriteLine( "Byte " + n + " differed " + one[n].ToString( "x" ) + " " + two[n].ToString( "x" ) ); } } for( bits = 1; bits < 28; bits++ ) { srg.Reset(); collector.Clear(); for( n = 0; n < ( 512 - bits ); n += bits ) { int value = srg.GetEntropy( bits, true ); collector.AddBits( (uint)value, bits ); //Console.WriteLine( "data is : " + value ); } { int final_value = srg.GetEntropy( 512 - n, false ); collector.AddBits( (uint)final_value, 512 - n ); } byte[] one = srg.entropy; byte[] two = collector.buffer; for( n = 0; n < 512 / 8; n++ ) { if( one[n] != two[n] ) Console.WriteLine( "Byte " + n + " differed " + one[n].ToString( "x" ) + " " + two[n].ToString( "x" ) ); } } }
public byte[] ComputeHash(Stream inputStream) { System.Security.Cryptography.SHA512 sha512Implementation = System.Security.Cryptography.SHA512.Create(); return(sha512Implementation.ComputeHash(inputStream)); }
int my_get_mask( byte[] data, int bits ) { uint result; int offset = 0; // how many bits were used of the first byte int first_used_bits = ( bits_used & 7 ); // how many bits are availablt in first byte (to align to byte read) int first_bits = 8 - first_used_bits; if( first_used_bits > 0 ) { if( bits <= first_bits ) { result = ( ( (uint)data[bits_used / 8] >> first_used_bits ) & my_mask_mask( bits ) ); bits_used += bits; return (int)result; } else { result = (uint)data[bits_used / 8] >> first_used_bits; bits -= first_bits; bits_used += first_bits; offset = first_bits; } } else { result = 0; } while( bits >= 8 ) { result |= (uint)data[(bits_used/8)] << offset; //result |= data[b++]; bits -= 8; offset += 8; bits_used += 8; } if( bits > 0 ) { result |= ( data[bits_used / 8] & my_mask_mask( bits ) ) << offset; bits_used += bits; } return (int)result; }
//[ScriptMethod(ResponseFormat = System.Web.Script.Services.ResponseFormat.Xml, XmlSerializeString = true)] public Apq.STReturn UserEditLoginPwd(string LoginPwd_C, string LoginPwd) { Apq.STReturn stReturn = new Apq.STReturn(); Apq.Web.SessionState.HttpSessionState ApqSession = new Apq.Web.SessionState.HttpSessionState(Session); if (!CheckLoginPage.CheckLogin(ref stReturn, ApqSession)) { return(stReturn); } // 检测旧密码 System.Security.Cryptography.SHA512 SHA512 = System.Security.Cryptography.SHA512.Create(); byte[] binLoginPwd_C = SHA512.ComputeHash(System.Text.Encoding.Unicode.GetBytes(LoginPwd_C)); string SqlLoginPwd_C = Apq.Data.SqlClient.Common.ConvertToSqlON(binLoginPwd_C); string SqlLoginPwd_DB = Apq.Data.SqlClient.Common.ConvertToSqlON(ApqSession.User.Rows[0]["LoginPwd"]); if (SqlLoginPwd_C != SqlLoginPwd_DB) { stReturn.NReturn = -1; stReturn.ExMsg = "原密码输入错误"; return(stReturn); } byte[] binLoginPwd = SHA512.ComputeHash(System.Text.Encoding.Unicode.GetBytes(LoginPwd)); using (SqlConnection SqlConn = new SqlConnection(Apq.DB.Common.GetSqlConnectionString("SqlConnectionString2"))) { SqlCommand sc = new SqlCommand("dtxc.dtxc_User_UpdateLoginPwd", SqlConn); sc.CommandType = CommandType.StoredProcedure; Apq.Data.Common.DbCommandHelper dch = new Apq.Data.Common.DbCommandHelper(sc); dch.AddParameter("rtn", 0, DbType.Int32); dch.AddParameter("ExMsg", stReturn.ExMsg, DbType.String, -1); dch.AddParameter("_OperID", ApqSession.UserID); dch.AddParameter("_OpTime", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff")); IPAddress ipa; if (IPAddress.TryParse(HttpContext.Current.Request.UserHostAddress, out ipa)) { dch.AddParameter("_OperIP", ipa.GetAddressBytes()); } dch.AddParameter("UserID", ApqSession.UserID); dch.AddParameter("LoginPwd", binLoginPwd); sc.Parameters["rtn"].Direction = ParameterDirection.ReturnValue; sc.Parameters["ExMsg"].Direction = ParameterDirection.InputOutput; SqlConn.Open(); sc.ExecuteNonQuery(); stReturn.NReturn = System.Convert.ToInt32(sc.Parameters["rtn"].Value); stReturn.ExMsg = sc.Parameters["ExMsg"].Value.ToString(); sc.Dispose(); SqlConn.Close(); } // 更新Session中的密码信息 ApqSession.User.Rows[0]["LoginPwd"] = binLoginPwd; // 返回客户端 stReturn.FNReturn = Apq.Data.SqlClient.Common.ConvertToSqlON(binLoginPwd); return(stReturn); }
//[ScriptMethod(ResponseFormat = System.Web.Script.Services.ResponseFormat.Xml, XmlSerializeString = true)] public Apq.STReturn Dinner_RegEmployee(string EmName, string LoginName, string LoginPwd) { Apq.STReturn stReturn = new Apq.STReturn(); if (EmName.Length < 1) { stReturn.NReturn = -1; stReturn.ExMsg = "姓名不允许为空"; return(stReturn); } if (LoginName.Length < 1) { stReturn.NReturn = -1; stReturn.ExMsg = "登录不允许为空"; return(stReturn); } if (LoginPwd.Length < 1) { stReturn.NReturn = -1; stReturn.ExMsg = "密码不允许为空"; return(stReturn); } System.Security.Cryptography.SHA512 SHA512 = System.Security.Cryptography.SHA512.Create(); byte[] binLoginPwd = SHA512.ComputeHash(System.Text.Encoding.Unicode.GetBytes(LoginPwd)); string SqlLoginPwd = Apq.Data.SqlClient.Common.ConvertToSqlON(binLoginPwd); DbConnection SqlConn = null; using (SqlConn = Apq.DBC.Common.CreateDBConnection("Dinner", ref SqlConn)) { Apq.Data.Common.DbConnectionHelper dbch = new Apq.Data.Common.DbConnectionHelper(SqlConn); DbCommand sc = SqlConn.CreateCommand(); sc.CommandText = "dbo.Dinner_RegEmployee"; sc.CommandType = CommandType.StoredProcedure; Apq.Data.Common.DbCommandHelper dch = new Apq.Data.Common.DbCommandHelper(sc); dch.AddParameter("rtn", 0, DbType.Int32); dch.AddParameter("ExMsg", stReturn.ExMsg, DbType.String, -1); //IPAddress ipa; //if (IPAddress.TryParse(HttpContext.Current.Request.UserHostAddress, out ipa)) //{ // dch.AddParameter("RegIP", ipa.GetAddressBytes()); //} dch.AddParameter("EmName", EmName); dch.AddParameter("LoginName", LoginName); dch.AddParameter("LoginPwd", binLoginPwd); //dch.AddParameter("Sex", Sex); //dch.AddParameter("PhotoUrl", PhotoUrl); //dch.AddParameter("Birthday", Birthday.ToString("yyyy-MM-dd HH:mm:ss.fff")); //dch.AddParameter("Alipay", Alipay); //dch.AddParameter("IntroUserID", IntroUserID); //dch.AddParameter("UserType", UserType); //dch.AddParameter("Expire", DateTime.Now.AddYears(10).ToString("yyyy-MM-dd HH:mm:ss.fff")); //dch.AddParameter("IDCard", IDCard); //dch.AddParameter("IDCard_Name", IDCard_Name); //dch.AddParameter("IDCard_Sex", IDCard_Sex); //dch.AddParameter("IDCard_PhotoUrl", IDCard_PhotoUrl); dch.AddParameter("EmID", 0, DbType.Int64); dch.AddParameter("LoginID", 0, DbType.Int64); sc.Parameters["rtn"].Direction = ParameterDirection.ReturnValue; sc.Parameters["ExMsg"].Direction = ParameterDirection.InputOutput; sc.Parameters["EmID"].Direction = ParameterDirection.InputOutput; sc.Parameters["LoginID"].Direction = ParameterDirection.InputOutput; SqlConn.Open(); sc.ExecuteNonQuery(); stReturn.NReturn = System.Convert.ToInt32(sc.Parameters["rtn"].Value); stReturn.ExMsg = sc.Parameters["ExMsg"].Value.ToString(); stReturn.POuts.Add(sc.Parameters["EmID"].Value); stReturn.POuts.Add(sc.Parameters["LoginID"].Value); stReturn.POuts.Add(LoginName); stReturn.POuts.Add(SqlLoginPwd); sc.Dispose(); SqlConn.Close(); } return(stReturn); }
public int GetEntropy( int bits, bool signed ) { int tmp; int partial_tmp = 0; // redundant init; this does not have to be initialized. int partial_bits = 0; if( bits > ( bits_avail - bits_used ) ) { if( bits_avail - bits_used > 0 ) { partial_bits = bits_avail - bits_used; partial_tmp = my_get_mask( entropy, partial_bits ); bits -= partial_bits; } GetBits(); } { tmp = my_get_mask( entropy, bits ); if( partial_bits > 0 ) { tmp = partial_tmp | ( tmp << partial_bits ); bits += partial_bits; // restore bit counter for signed computation } if( signed ) if( ( tmp & ( 1 << ( bits - 1 ) ) ) != 0 ) { uint negone = ~(uint)0; negone <<= bits; return (int)( (uint)tmp | negone ); } } return ( tmp ); }
//[ScriptMethod(ResponseFormat = System.Web.Script.Services.ResponseFormat.Xml, XmlSerializeString = true)] public STReturn dtxc_Reg_UserName(string Name, string UserName, string LoginPwd, short Sex, string PhotoUrl, long IntroUserID, string Alipay, int UserType , DateTime Birthday, string IDCard, string IDCard_Name, short IDCard_Sex, string IDCard_PhotoUrl) { STReturn stReturn = new STReturn(); if (LoginPwd.Length < 1) { stReturn.NReturn = -1; stReturn.ExMsg = "密码不允许为空"; return(stReturn); } System.Security.Cryptography.SHA512 SHA512 = System.Security.Cryptography.SHA512.Create(); byte[] binLoginPwd = SHA512.ComputeHash(System.Text.Encoding.Unicode.GetBytes(LoginPwd)); using (SqlConnection SqlConn = new SqlConnection(Apq.DB.Common.GetSqlConnectionString("SqlConnectionString2"))) { SqlCommand sc = new SqlCommand("dtxc.dtxc_Reg_UserName", SqlConn); sc.CommandType = CommandType.StoredProcedure; Apq.Data.Common.DbCommandHelper dch = new Apq.Data.Common.DbCommandHelper(sc); dch.AddParameter("rtn", 0, DbType.Int32); dch.AddParameter("ExMsg", stReturn.ExMsg, DbType.String, -1); IPAddress ipa; if (IPAddress.TryParse(HttpContext.Current.Request.UserHostAddress, out ipa)) { dch.AddParameter("RegIP", ipa.GetAddressBytes()); } dch.AddParameter("Name", Name); dch.AddParameter("UserName", UserName); dch.AddParameter("LoginPwd", binLoginPwd); dch.AddParameter("Sex", Sex); dch.AddParameter("PhotoUrl", PhotoUrl); dch.AddParameter("Birthday", Birthday.ToString("yyyy-MM-dd HH:mm:ss.fff")); dch.AddParameter("Alipay", Alipay); dch.AddParameter("IntroUserID", IntroUserID); dch.AddParameter("UserType", UserType); dch.AddParameter("Expire", DateTime.Now.AddYears(10).ToString("yyyy-MM-dd HH:mm:ss.fff")); dch.AddParameter("IDCard", IDCard); dch.AddParameter("IDCard_Name", IDCard_Name); dch.AddParameter("IDCard_Sex", IDCard_Sex); dch.AddParameter("IDCard_PhotoUrl", IDCard_PhotoUrl); dch.AddParameter("UserID", 0, DbType.Int64); sc.Parameters["rtn"].Direction = ParameterDirection.ReturnValue; sc.Parameters["ExMsg"].Direction = ParameterDirection.InputOutput; sc.Parameters["UserID"].Direction = ParameterDirection.InputOutput; SqlConn.Open(); sc.ExecuteNonQuery(); stReturn.NReturn = System.Convert.ToInt32(sc.Parameters["rtn"].Value); stReturn.ExMsg = sc.Parameters["ExMsg"].Value.ToString(); stReturn.POuts = new object[] { sc.Parameters["UserID"].Value }; sc.Dispose(); SqlConn.Close(); } return(stReturn); }
private static byte[] ComputeSingleSha(byte[] data) { using System.Security.Cryptography.SHA512 sysSha = System.Security.Cryptography.SHA512.Create(); return(sysSha.ComputeHash(data)); }
/// <summary> /// Gets the sh a512 hash as byte array. /// </summary> /// <param name="data">The data.</param> /// <returns></returns> public static byte[] GetSHA512HashAsByteArray(byte[] data) { System.Security.Cryptography.SHA512 sha512Implementation = System.Security.Cryptography.SHA512.Create(); return(sha512Implementation.ComputeHash(data)); }