public static bool VerifyL1Signature(this string signature, string secret, string message) { Logger.LogEnter(LoggerBase.Args(signature, message, "***secret***")); bool signatureValid = ApiAuthorization.L1Signature(message, secret) == signature; Logger.LogExit(LoggerBase.Args(signatureValid)); return(signatureValid); }
public static String Token( string realm , string authPrefix , HttpMethod httpMethod , Uri urlPath , string appId , string secret = null , ApiList formList = null , RSA privateKey = null , string nonce = null , string timestamp = null , string version = "1.0") { Logger.LogEnter(LoggerBase.Args(realm, authPrefix, httpMethod, urlPath, appId, secret, formList == null ? null : formList.ToFormData(), privateKey, nonce, timestamp, version)); Logger.LogDebug("URL:: {0}", urlPath); authPrefix = authPrefix.ToLower(); // Generate the nonce value nonce = nonce ?? ApiAuthorization.NewNonce().ToString(); timestamp = timestamp ?? ApiAuthorization.NewTimestamp().ToString(); SignatureMethod signatureMethod = SignatureMethod.HMACSHA256; if (secret == null) { signatureMethod = SignatureMethod.SHA256withRSA; } String baseString = BaseString(authPrefix, signatureMethod , appId, urlPath, httpMethod , formList, nonce, timestamp, version); String base64Token = ""; if (secret != null) { base64Token = baseString.L1Signature(secret); } else { base64Token = baseString.L2Signature(privateKey); } var tokenList = new ApiList(); tokenList.Add("realm", realm); tokenList.Add(authPrefix + "_timestamp", timestamp); tokenList.Add(authPrefix + "_nonce", nonce); tokenList.Add(authPrefix + "_app_id", appId); tokenList.Add(authPrefix + "_signature_method", signatureMethod.ToString()); tokenList.Add(authPrefix + "_version", version); tokenList.Add(authPrefix + "_signature", base64Token); string authorizationToken = string.Format("{0} {1}", authPrefix.Substring(0, 1).ToUpperInvariant() + authPrefix.Substring(1), tokenList.ToString(",", false, true)); Logger.LogDebug("Token :: {0}", authorizationToken); Logger.LogExit(LoggerBase.Args(authorizationToken)); return(authorizationToken); }