/// <summary> /// Gets the hash code /// </summary> /// <returns>Hash code</returns> public override int GetHashCode() { unchecked // Overflow is fine, just wrap { var hashCode = 41; // Suitable nullity checks etc, of course :) if (CardholderName != null) { hashCode = hashCode * 59 + CardholderName.GetHashCode(); } if (Cryptogram != null) { hashCode = hashCode * 59 + Cryptogram.GetHashCode(); } if (Dpan != null) { hashCode = hashCode * 59 + Dpan.GetHashCode(); } if (Eci != null) { hashCode = hashCode * 59 + Eci.GetHashCode(); } if (ExpiryDate != null) { hashCode = hashCode * 59 + ExpiryDate.GetHashCode(); } return(hashCode); } }
/// <summary> /// 处理原始令牌 /// </summary> /// <param name="orginalToken">原始令牌</param> /// <returns>处理过的令牌</returns> private static string HandleOrginalToken(string orginalToken) { if (string.IsNullOrWhiteSpace(orginalToken)) { return(null); } //如果app传过来的值没有编码:1、带“/”会被截断导致出错,2、“+”会urldecode为空格,空格补“+” var token = orginalToken.Replace(" ", "+"); //补+的问题 //处理app传过来的值,有可能被多次encoder的情况 for (int index = 0; index < 5; index++) { if (token.IndexOf("%") < 0) { break; } token = System.Web.HttpUtility.UrlDecode(token, System.Text.Encoding.UTF8); if (token.IndexOf("%") < 0) { break; } } token = token.Replace("-", "+").Replace("_", "/").Replace("*", "="); return(Cryptogram.DecryptUserToken(token)); }
/// <summary> /// 解密手机号 /// </summary> /// <param name="enMobile">加密的手机号</param> /// <returns></returns> public static string DecryptMobile(string enMobile) { if (string.IsNullOrWhiteSpace(enMobile)) { return(string.Empty); } return(Cryptogram.DecryptPassword(enMobile)); }
/// <summary> /// 加密手机号 /// </summary> /// <param name="mobile"></param> /// <returns></returns> public static string EncryptMobile(string mobile) { if (string.IsNullOrWhiteSpace(mobile)) { return(string.Empty); } return(Cryptogram.EncryptPassword(mobile)); }
public static string ReadEncrypt(string path, EncryptType encrypt = EncryptType.AES) { if (File.Exists(path)) { byte[] buffer = File.ReadAllBytes(path); return(Cryptogram.Encrypt(Encoding.Default.GetString(buffer), encrypt)); } return(string.Empty); }
public static SubSelect GetSubData(byte[] data, HandshakeResponse handresponse) { SubSelect subdata = new SubSelect(); if (!VerificationTools.HashCheck(data.ToList())) { return(null); } var decr = Cryptogram.Decrypt(data, handresponse); return(AnalysisSubSelect(decr)); }
public static void WriteEncrypt(string path, string content, EncryptType encrypt = EncryptType.AES) { try { byte[] buffer = Encoding.Default.GetBytes(Cryptogram.Decrypt(content, encrypt)); CreateDirectory(Path.GetDirectoryName(path)); File.WriteAllBytes(path, buffer); } catch (Exception e) { Debuger.LogException(Author.File, e); } }
/// <summary> /// Returns true if Model3dsData instances are equal /// </summary> /// <param name="other">Instance of Model3dsData to be compared</param> /// <returns>Boolean</returns> public bool Equals(ThreeDSEnrollment other) { if (ReferenceEquals(null, other)) { return(false); } if (ReferenceEquals(this, other)) { return(true); } return (( Downgraded == other.Downgraded || Downgraded != null && Downgraded.Equals(other.Downgraded) ) && ( Enrolled == other.Enrolled || Enrolled != null && Enrolled.Equals(other.Enrolled) ) && ( SignatureValid == other.SignatureValid || SignatureValid != null && SignatureValid.Equals(other.SignatureValid) ) && ( AuthenticationResponse == other.AuthenticationResponse || AuthenticationResponse != null && AuthenticationResponse.Equals(other.AuthenticationResponse) ) && ( Cryptogram == other.Cryptogram || Cryptogram != null && Cryptogram.Equals(other.Cryptogram) ) && ( Xid == other.Xid || Xid != null && Xid.Equals(other.Xid) ) && ( Version == other.Version || Version != null && Version.Equals(other.Version) )); }
/// <summary> /// 获取有效验证码(最近五分钟) /// </summary> /// <param name="mobile">手机号</param> /// <returns></returns> public static VerifyCodeInfoEntity GetValid(string mobile, VerifyCodeType codeType) { if (string.IsNullOrWhiteSpace(mobile)) { return(null); } var sql = "select top 1 * from dbo.VerifyCodeInfo t where t.mobile = @mobile and t.VerifyCodeType = @codeType and t.[status] = 1 and t.AddTime between @startTime and @endTime order by t.AddTime DESC;"; using (var conn = new SqlConnection(ConnectionString.DB_IQFUser)) { var enMobile = Cryptogram.EncryptPassword(mobile); var startTime = DateTime.Now.AddSeconds(-300); var entity = conn.Query <VerifyCodeInfoEntity>(sql, new { mobile = enMobile, codeType = codeType, startTime = startTime, endTime = DateTime.Now }).FirstOrDefault(); return(entity); } }
/// <summary> /// 用户对象,生成令牌 /// </summary> /// <param name="user">用户对象</param> /// <param name="UserToken">令牌</param> /// <returns>true/false</returns> public static string GenUserToken(UserTokenModel user) { if (user == null || user.UserID <= 0) { return(null); } StringBuilder sb = new StringBuilder(); sb.Append(user.UserID); sb.Append(Separator); sb.Append(user.Mobile ?? string.Empty); string strUserToken = Cryptogram.EncryptUserToken(sb.ToString()); strUserToken = strUserToken.Replace("+", "-").Replace("/", "_").Replace("=", "*"); return(System.Web.HttpUtility.UrlEncode(strUserToken, System.Text.Encoding.UTF8)); }
public Byte[] GetFinalArray() { List <Byte> listFinalBody = new List <byte>(); listFinalBody.Add(Convert.ToByte((machineAddress & 0xFF000000) >> 24)); listFinalBody.Add(Convert.ToByte((machineAddress & 0xFF0000) >> 16)); listFinalBody.Add(Convert.ToByte((machineAddress & 0xFF00) >> 8)); listFinalBody.Add(Convert.ToByte(machineAddress & 0xFF)); listFinalBody.Add(Convert.ToByte(number)); listFinalBody.Add(Convert.ToByte(dotPwoer)); listFinalBody.Add(Convert.ToByte((request & 0xFF00000000000000) >> 56)); listFinalBody.Add(Convert.ToByte((request & 0xFF000000000000) >> 48)); listFinalBody.Add(Convert.ToByte((request & 0xFF0000000000) >> 40)); listFinalBody.Add(Convert.ToByte((request & 0xFF00000000) >> 32)); listFinalBody.Add(Convert.ToByte((request & 0xFF000000) >> 24)); listFinalBody.Add(Convert.ToByte((request & 0xFF0000) >> 16)); listFinalBody.Add(Convert.ToByte((request & 0xFF00) >> 8)); listFinalBody.Add(Convert.ToByte(request & 0xFF)); listFinalBody.Add(share1.GetShare1Byte(GetShare1Enum())); listFinalBody.Add(share2.GetShare2Byte()); List <Byte> listFinal = new List <byte>(); listFinal.Add(Convert.ToByte(head)); listFinal.Add(Convert.ToByte(dataBelong)); listFinal.Add(Convert.ToByte((handshakeSecretKey & 0xFF00) >> 8)); listFinal.Add(Convert.ToByte(handshakeSecretKey & 0xFF)); listFinal.AddRange(Cryptogram.Encryption(listFinalBody, listFinal[3], listFinal[2])); listFinal.Add(Convert.ToByte(VerificationTools.HashCalc(listFinal))); return(listFinal.ToArray()); }
/// <summary> /// Returns true if DecryptedPaymentData instances are equal /// </summary> /// <param name="other">Instance of DecryptedPaymentData to be compared</param> /// <returns>Boolean</returns> public bool Equals(DecryptedPaymentData other) { if (ReferenceEquals(null, other)) { return(false); } if (ReferenceEquals(this, other)) { return(true); } return (( CardholderName == other.CardholderName || CardholderName != null && CardholderName.Equals(other.CardholderName) ) && ( Cryptogram == other.Cryptogram || Cryptogram != null && Cryptogram.Equals(other.Cryptogram) ) && ( Dpan == other.Dpan || Dpan != null && Dpan.Equals(other.Dpan) ) && ( Eci == other.Eci || Eci != null && Eci.Equals(other.Eci) ) && ( ExpiryDate == other.ExpiryDate || ExpiryDate != null && ExpiryDate.Equals(other.ExpiryDate) )); }
/// <summary> /// Gets the hash code /// </summary> /// <returns>Hash code</returns> public override int GetHashCode() { unchecked // Overflow is fine, just wrap { var hashCode = 41; // Suitable nullity checks etc, of course :) if (Downgraded != null) { hashCode = hashCode * 59 + Downgraded.GetHashCode(); } if (Enrolled != null) { hashCode = hashCode * 59 + Enrolled.GetHashCode(); } if (SignatureValid != null) { hashCode = hashCode * 59 + SignatureValid.GetHashCode(); } if (AuthenticationResponse != null) { hashCode = hashCode * 59 + AuthenticationResponse.GetHashCode(); } if (Cryptogram != null) { hashCode = hashCode * 59 + Cryptogram.GetHashCode(); } if (Xid != null) { hashCode = hashCode * 59 + Xid.GetHashCode(); } if (Version != null) { hashCode = hashCode * 59 + Version.GetHashCode(); } return(hashCode); } }
/// <summary> /// 保存验证码 /// </summary> public static bool Insert(VerifyCodeType verifyCodeType, string mobile, string verifyCode, int packType, int status, string comment) { if (string.IsNullOrWhiteSpace(mobile) || string.IsNullOrWhiteSpace(verifyCode)) { return(false); } var sql = "INSERT INTO [dbo].[VerifyCodeInfo]([Mobile],[VerifyCode],[VerifyCodeType],[Status],[Comment],[PackType]) VALUES(@Mobile,@VerifyCode,@VerifyCodeType,@Status,@Comment,@PackType);"; using (var conn = new SqlConnection(ConnectionString.DB_IQFUser)) { var count = conn.Execute(sql, new { verifyCodeType = verifyCodeType, mobile = Cryptogram.EncryptPassword(mobile), verifyCode = verifyCode, packType = packType, status = status, comment }); return(count > 0); } }
void CheckCollectables(Collider2D collider) { if (collider.CompareTag("Book")) { Book book = collider.gameObject.GetComponent <Book>(); char bookChar = book.bookChar; //Debug.Log("collided with book with char: " + bookChar); Cryptogram crypto = GameObject.Find("Cryptogram").GetComponent <Cryptogram>(); crypto.UnscrambleValue(bookChar); crypto.Scramble(crypto.message); GameObject.Destroy(book.gameObject); } else if (collider.CompareTag("Chest")) { Chest chest = collider.gameObject.GetComponent <Chest>(); char chestChar = chest.storedChar; //Debug.Log("opened chest with char: " + chestChar); Cryptogram crypto = GameObject.Find("Cryptogram").GetComponent <Cryptogram>(); // if this one is already open if (chest.gameObject.GetComponent <Animator>().GetBool("open")) { // do nothing } // open in correct order else if (crypto.message[crypto.openChests].Equals(chestChar)) { chest.gameObject.GetComponent <Animator>().SetBool("open", true); crypto.openChests++; } else { crypto.CloseAllChests(); } } // collect the map else if (collider.CompareTag("Map")) { GameObject.Find("Minimap").GetComponent <Camera>().enabled = true; GameObject.Destroy(collider.gameObject); } // collect the boots else if (collider.CompareTag("Boots")) { speedMod -= 0.5f; GameObject.Destroy(collider.gameObject); } // collect the better boots else if (collider.CompareTag("BetterBoots")) { speedMod -= 0.5f; GameObject.Destroy(collider.gameObject); } // collect the attack else if (collider.CompareTag("AttackEnabler")) { canAttack = true; GameObject.Destroy(collider.gameObject); } // collect the food else if (collider.CompareTag("Food")) { IncreaseStamina(10f); GameObject.Destroy(collider.gameObject); } }
static void Main(string[] args) { Console.WriteLine("Введите номер задачи:\n" + "1 - Вычисление множества запретных биграмм языка открытых сообщений (text.txt)\n" + "2 - Создание перестановки текста (message.txt) по ключу (key.txt) длины n (n.txt)\n" + "3 - Построение вспомогательной таблицы для анализа шифра перестановки при известной длине периода (n.txt)\n" + "4 - Построение ориентированного дерева возможных перестановок (anticipatedKey.txt)\n" + "5 - Перебор ключей по ориентированному лесу возможных перестановок (decipher.txt) "); int choice = int.Parse(Console.ReadLine()); switch (choice) { case 1: { Biagram biagram = new Biagram(); HashSet <String> existBiagram = biagram.GetBiagramOpenText("text.txt"); HashSet <String> alphBiagram = biagram.GetBiagramAlph("alph.txt"); String[] existArray = existBiagram.ToArray(); String[] alphArray = alphBiagram.ToArray(); IEnumerable <String> notExist = alphArray.Except(existArray); using (StreamWriter sw = File.AppendText("notExistBiagram.txt")) { foreach (var temp in notExist) { sw.WriteLine(temp); } } break; } case 2: { GenerateMonocyclicTransposition transposition = new GenerateMonocyclicTransposition(); Cryptogram cryptogram = new Cryptogram(); break; } case 3: { Table table = new Table(); break; } case 4: { Table table = new Table("table.txt"); CreateInpossibleTransposition(table); break; } case 5: { List <int[]> key = ReadKey("anticipatedKey.txt"); Decipher(key); break; } default: break; } }
/// <summary> /// 加密密码 /// </summary> /// <param name="password"></param> /// <returns></returns> public static string EncryptPassword(string password) { var value = "IFQ" + password; return(Cryptogram.GetMD5(value)); }