bool VerifyCode(string discountCode)
{
SHA1Managed hash = new SHA1Managed();
byte[] codeHash = hash.ComputeHash(Encoding.Unicode.GetBytes(discountCode));
byte[] secretCode = new byte[] { 116,46,130,122,36,234,158,125,163,122,157,186,64,142,51,153,113,79,1,42 };
if (codeHash.Length != secretCode.Length) return false;
for (int i = 0; i < codeHash.Length; i++)
if (codeHash[i] != secretCode[i]) return false;
WebServiceSoapClient client = new WebServiceSoapClient();
client.ApplyDiscountCode();
return true;
}
SHA256Managed 實作 SHA-256。Web Forms 代碼運行於伺服器,Silverlight 運行於客戶端,兩者信任邊界截然不同,切勿混淆。