Advertisement
Guest User

MacData Generation

a guest
Jan 22nd, 2020
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.30 KB | None | 0 0
  1. static string hashMacData(string rrn, string creditAmount, string creditAccount, string key)
  2.         {
  3.             if(string.IsNullOrWhiteSpace(rrn)) throw new ArgumentNullException(nameof(rrn));
  4.  
  5.             if(string.IsNullOrWhiteSpace(creditAmount)) throw new ArgumentNullException(nameof(creditAmount));
  6.  
  7.             if(string.IsNullOrWhiteSpace(creditAccount)) throw new ArgumentNullException(nameof(creditAccount));
  8.  
  9.             if(string.IsNullOrWhiteSpace(key)) throw new ArgumentNullException(nameof(key));
  10.  
  11.             var entireStringToHash = rrn + "&" + creditAmount + "&" + creditAccount + "&" + key;
  12.  
  13.             var saltbytes = Encoding.UTF8.GetBytes(key);
  14.  
  15.             var entireStringToHashByte = Encoding.UTF8.GetBytes(entireStringToHash);
  16.  
  17.             byte[] concatenatedByteWithSaltArray = new byte[saltbytes.Length + entireStringToHashByte.Length];
  18.  
  19.             string result = string.Empty;
  20.  
  21.             using (HashAlgorithm  shaM = new SHA512Managed()){
  22.                 saltbytes.CopyTo(concatenatedByteWithSaltArray, 0);
  23.                 entireStringToHashByte.CopyTo(concatenatedByteWithSaltArray, saltbytes.Length);
  24.  
  25.                 result = Convert.ToBase64String(shaM.ComputeHash(concatenatedByteWithSaltArray));
  26.             }
  27.  
  28.             return result;
  29.         }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement