/// <summary> /// Generate the passport signature needed for creating the TokenPassport Object /// /// </summary> /// <param name="account">ID of the NetSuite accoutn you intend to connect to</param> /// <param name="consumerKey">Generated by creating an integration record</param> /// <param name="consumerSecret">Generated by creating an integration record</param> /// <param name="tokenId">Generated when a token is created.</param> /// <param name="tokenSecret">Generated when a token is created.</param> /// <returns>Generated TokenPassport Signature</returns> private static TokenPassportSignature getPassportSignature(string account, string consumerKey, string consumerSecret, string tokenId, string tokenSecret) { string signature; string algorithm = "HMAC-SHA1"; string baseString = string.Format("{0}&{1}&{2}&{3}&{4}", account, consumerKey, tokenId, _nonce, _timestamp); string keyString = string.Format("{0}&{1}", consumerSecret, tokenSecret); var encoding = new System.Text.ASCIIEncoding(); byte[] keyByte = encoding.GetBytes(keyString); byte[] messageBytes = encoding.GetBytes(baseString); using (var myhmacsha1 = new HMACSHA1(keyByte)) { byte[] hashmessage = myhmacsha1.ComputeHash(messageBytes); signature = Convert.ToBase64String(hashmessage); } TokenPassportSignature passportSignature = new TokenPassportSignature { algorithm = algorithm, Value = signature }; return(passportSignature); }
private static TokenPassport CreateTokenPassport() { Stopwatch sw = new Stopwatch(); string account = "606500_SB1"; string consumerKey = "e0a74c549bfa07f950eff91b41292ab3bc4cf9e62718cea85fc5fe87950272e3"; string consumerSecret = "cfeb3ac9ac84ad933c08e1de083660204cbf3844231d75341603f1d532f1d4eb"; string tokenId = "9bcab909033a99936c7e569b6432be961f432c4336131f88779883f4b9d743c2"; string tokenSecret = "f027714435a5b30aa7af437a5a93b129b2c71c41db4a1d5dd6202abda00a3016"; string nonce = ComputeNonce(); long timestamp = ComputeTimestamp(); sw.Start(); TokenPassportSignature signature = ComputeSignature(account, consumerKey, consumerSecret, tokenId, tokenSecret, nonce, timestamp); TokenPassport tokenPassport = new TokenPassport(); tokenPassport.account = account; tokenPassport.consumerKey = consumerKey; tokenPassport.token = tokenId; tokenPassport.nonce = nonce; tokenPassport.timestamp = timestamp; tokenPassport.signature = signature; sw.Stop(); //_auditLog.AddLogDetails(AuditLogType.Information, $"{DateTime.UtcNow} Timestamp: {timestamp}, Token: {tokenId}, signature generation, ms: {sw.ElapsedMilliseconds}"); return(tokenPassport); }
private TokenPassportSignature ComputeSignature(string compId, string consumerKey, string consumerSecret, string tokenId, string tokenSecret, string nonce, long timestamp) { string baseString = compId + "&" + consumerKey + "&" + tokenId + "&" + nonce + "&" + timestamp; string key = consumerSecret + "&" + tokenSecret; string signature = ""; var encoding = new System.Text.ASCIIEncoding(); byte[] keyBytes = encoding.GetBytes(key); byte[] baseStringBytes = encoding.GetBytes(baseString); using (var hmacSha1 = new HMACSHA256(keyBytes)) { byte[] hashBaseString = hmacSha1.ComputeHash(baseStringBytes); signature = Convert.ToBase64String(hashBaseString); } TokenPassportSignature sign = new TokenPassportSignature(); sign.algorithm = "HMAC-SHA256"; sign.Value = signature; return(sign); }
private TokenPassportSignature ComputeSignature(string acctNumber, string tokenId, string tokenSecret, string nonce, long timestamp) { string baseString = $"{acctNumber}&{_consumerKey}&{tokenId}&{nonce}&{timestamp}"; string key = string.Concat(_consumerSecret, "&", tokenSecret); string signature = ""; var encoding = new ASCIIEncoding(); byte[] keyBytes = encoding.GetBytes(key); byte[] baseStringBytes = encoding.GetBytes(baseString); using (var hmacSha1 = new HMACSHA256(keyBytes)) { byte[] hashBaseString = hmacSha1.ComputeHash(baseStringBytes); signature = Convert.ToBase64String(hashBaseString); } TokenPassportSignature sign = new TokenPassportSignature { algorithm = "HMAC-SHA256", Value = signature }; return(sign); }
public TokenPassport CreateTokenPassport() { string account = ConfigurationManager.AppSettings["login.acct"]; string consumerKey = ConfigurationManager.AppSettings["login.tbaConsumerKey"]; string consumerSecret = ConfigurationManager.AppSettings["login.tbaConsumerSecret"]; string tokenId = ConfigurationManager.AppSettings["login.tbaTokenId"]; string tokenSecret = ConfigurationManager.AppSettings["login.tbaTokenSecret"]; string nonce = ComputeNonce(); long timestamp = ComputeTimestamp(); TokenPassportSignature signature = ComputeSignature(account, consumerKey, consumerSecret, tokenId, tokenSecret, nonce, timestamp); TokenPassport tokenPassport = new TokenPassport(); tokenPassport.account = account; tokenPassport.consumerKey = consumerKey; tokenPassport.token = tokenId; tokenPassport.nonce = nonce; tokenPassport.timestamp = timestamp; tokenPassport.signature = signature; return(tokenPassport); }
public static TokenPassportSignature GenerateSignature(string nonce, long timestamp) { string accountId = ConfigurationManager.AppSettings["AccountID"]; string consumerKey = ConfigurationManager.AppSettings["ConsumerKey"]; string tokenId = ConfigurationManager.AppSettings["TokenId"]; string consumerSecret = ConfigurationManager.AppSettings["ConsumerSecret"]; string tokenSecret = ConfigurationManager.AppSettings["TokenSecret"]; //Creating Base String string baseString = accountId + "&" + consumerKey + "&" + tokenId + "&" + nonce + "&" + timestamp.ToString(); //Creating Signing Key string key = consumerSecret + "&" + tokenSecret; string signature = ""; var encoding = new System.Text.ASCIIEncoding(); byte[] keyByte = encoding.GetBytes(key); byte[] messageBytes = encoding.GetBytes(baseString); //Signing the base string using the signing key using HMACSHA1 algorithm using (var myhmacsha1 = new HMACSHA1(keyByte)) { byte[] hashmessage = myhmacsha1.ComputeHash(messageBytes); signature = Convert.ToBase64String(hashmessage); } TokenPassportSignature tokenPassportSignature = new TokenPassportSignature(); tokenPassportSignature.Value = signature; tokenPassportSignature.algorithm = "HMAC-SHA1"; return(tokenPassportSignature); }