daily pastebin goal
94%
SHARE
TWEET

Untitled

a guest Jan 20th, 2019 64 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Security.Cryptography;
  5. using System.Text;
  6.  
  7. namespace StarBank.Bank_Stuffs
  8. {
  9.     class BankSignatureGenerator
  10.     {
  11.         public void UpdateSignature(Bank bank)
  12.         {
  13.             //Start with author number, player number, and bank name
  14.             StringBuilder inputString = new StringBuilder();
  15.             inputString.Append(bank.BankInfo.AuthorNumber);
  16.             inputString.Append(bank.BankInfo.PlayerNumber);
  17.             inputString.Append(bank.BankInfo.Name);
  18.  
  19.             //Append each section name (ordered by ASCII values, not dictionary-ordering)...
  20.             foreach(Bank.Section section in bank.Sections.OrderBy(o => o.Name, StringComparer.Ordinal))
  21.             {
  22.                 inputString.Append(section.Name);
  23.                
  24.                 //And between those, each key-name/value
  25.                 foreach(Bank.Key key in section.Keys.OrderBy(o => o.Name, StringComparer.Ordinal))
  26.                 {
  27.                     inputString.Append(key.Name);
  28.                     inputString.Append("Value");
  29.                     inputString.Append(key.Type);
  30.                     inputString.Append(key.Value);
  31.                 }
  32.             }
  33.  
  34.             //Finally, set the signature on the bank by taking the hash of the string
  35.             bank.Signature = Sha1Hash(inputString.ToString());
  36.         }
  37.  
  38.         private string Sha1Hash(string hashMe)
  39.         {
  40.             byte[] signatureInputBytes = Encoding.ASCII.GetBytes(hashMe);
  41.             SHA1CryptoServiceProvider sha1Provider = new SHA1CryptoServiceProvider();
  42.             byte[] hash = sha1Provider.ComputeHash(signatureInputBytes);
  43.             return BitConverter.ToString(hash).Replace("-", "");
  44.         }
  45.     }
  46. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top