Exemplo n.º 1
0
            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));
            }
Exemplo n.º 2
0
        // Token: 0x0600019B RID: 411 RVA: 0x0000B49C File Offset: 0x0000969C
        public static byte[] ComputeHash(string[] hashComponents, CryptoKeyPayloadType payloadKey, byte version)
        {
            HMAC hmacforCryptoKey = HashUtility.GetHMACForCryptoKey(payloadKey, version);

            byte[] bytes = Encoding.UTF8.GetBytes(string.Join(string.Empty, hashComponents));
            return(hmacforCryptoKey.ComputeHash(bytes));
        }
Exemplo n.º 3
0
 public SignedUrl(CryptoKeyPayloadType payloadType, string plaintextPayload)
 {
     this.PayloadType  = payloadType;
     this.UtcTimestamp = DateTime.UtcNow;
     this.Payload      = CryptoUtils.Encrypt(Encoding.UTF8.GetBytes(plaintextPayload), payloadType, out this.keyVersion, out this.InitializationVector);
     string[] hashComponents = new string[]
     {
         this.ToQueryStringFragment(null, false)
     };
     this.MessageAuthenticationCode = HashUtility.ComputeHash(hashComponents, this.HashTypeForPayload);
 }
Exemplo n.º 4
0
        // Token: 0x0600019D RID: 413 RVA: 0x0000B4D8 File Offset: 0x000096D8
        private static HMAC GetHMACForCryptoKey(CryptoKeyPayloadType payloadKey, byte version)
        {
            HMAC             hmac         = null;
            CryptographicKey keyByPayload = CryptoKeyStore.GetKeyByPayload(payloadKey);

            if (version == 0)
            {
                hmac     = HMAC.Create("HMACSHA1");
                hmac.Key = keyByPayload.Key;
            }
            else if (version == 1)
            {
                hmac     = HMAC.Create(keyByPayload.Algorithm.Name);
                hmac.Key = keyByPayload.Key;
            }
            return(hmac);
        }
Exemplo n.º 5
0
 // Token: 0x0600019C RID: 412 RVA: 0x0000B4CE File Offset: 0x000096CE
 public static byte[] ComputeHash(string[] hashComponents, CryptoKeyPayloadType payloadKey)
 {
     return(HashUtility.ComputeHash(hashComponents, payloadKey, 1));
 }