public string ToQueryStringFragment(NameValueCollection additionalParameters, bool includeHMAC = true) { NameValueCollection nameValueCollection = new NameValueCollection(); if (this.KeyVersion > 1) { nameValueCollection.Add("pt", ((int)this.PayloadType).ToString(NumberFormatInfo.InvariantInfo)); } else { CryptoKeyPayloadType payloadType = this.PayloadType; if (payloadType != CryptoKeyPayloadType.SvmFeedbackEncryption) { throw new InvalidOperationException(string.Format("Key of type {0} is not supported by legacy payloads, Key version must be greater than 1", Enum.GetName(typeof(CryptoKeyPayloadType), this.PayloadType))); } AuthkeyAuthenticationRequest.SignedUrl.LegacyPayloadType legacyPayloadType = AuthkeyAuthenticationRequest.SignedUrl.LegacyPayloadType.SvmFeedback; NameValueCollection nameValueCollection2 = nameValueCollection; string name = "pt"; int num = (int)legacyPayloadType; nameValueCollection2.Add(name, num.ToString(NumberFormatInfo.InvariantInfo)); } nameValueCollection.Add("kv", this.KeyVersion.ToString(NumberFormatInfo.InvariantInfo)); nameValueCollection.Add("ts", this.UtcTimestamp.ToFileTimeUtc().ToString(NumberFormatInfo.InvariantInfo)); nameValueCollection.Add("iv", AuthkeyAuthenticationRequest.UrlEncodeBase64String(Convert.ToBase64String(this.InitializationVector))); nameValueCollection.Add("authKey", AuthkeyAuthenticationRequest.UrlEncodeBase64String(Convert.ToBase64String(this.Payload))); if (includeHMAC && this.MessageAuthenticationCode != null) { nameValueCollection.Add("hmac", AuthkeyAuthenticationRequest.UrlEncodeBase64String(Convert.ToBase64String(this.MessageAuthenticationCode))); } if (additionalParameters != null) { nameValueCollection.Add(additionalParameters); } return(AuthkeyAuthenticationRequest.ConstructQueryString(nameValueCollection)); }
public SignedUrl(NameValueCollection queryString) { this.KeyVersion = byte.Parse(queryString["kv"], NumberFormatInfo.InvariantInfo); if (this.KeyVersion > 1) { this.PayloadType = (CryptoKeyPayloadType)int.Parse(queryString["pt"], NumberFormatInfo.InvariantInfo); } else { AuthkeyAuthenticationRequest.SignedUrl.LegacyPayloadType legacyPayloadType = (AuthkeyAuthenticationRequest.SignedUrl.LegacyPayloadType) int.Parse(queryString["pt"], NumberFormatInfo.InvariantInfo); AuthkeyAuthenticationRequest.SignedUrl.LegacyPayloadType legacyPayloadType2 = legacyPayloadType; if (legacyPayloadType2 != AuthkeyAuthenticationRequest.SignedUrl.LegacyPayloadType.SvmFeedback) { throw new SecurityException("failed to parse query string collection"); } this.PayloadType = CryptoKeyPayloadType.SvmFeedbackEncryption; } this.UtcTimestamp = DateTime.FromFileTimeUtc(long.Parse(queryString["ts"], NumberFormatInfo.InvariantInfo)); this.InitializationVector = Convert.FromBase64String(AuthkeyAuthenticationRequest.UrlDecodeBase64String(queryString["iv"])); this.Payload = Convert.FromBase64String(AuthkeyAuthenticationRequest.UrlDecodeBase64String(queryString["authKey"])); this.MessageAuthenticationCode = Convert.FromBase64String(AuthkeyAuthenticationRequest.UrlDecodeBase64String(queryString["hmac"])); }