// Decompiled with JetBrains decompiler
// Type: Microsoft.InfoCards.SymmetricCryptoSession
// Assembly: infocard, Version=3.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
// MVID: 516D8B44-4448-4D2C-8B8E-FFBB3FFE472B
// Assembly location: C:\Users\Administrateur\Downloads\Virusshare-00000-msil\Virus.Win32.Expiro.w-69bb73081eac86b8cf86f45e33515d0095855636967076e2b593d7a30cd80a07.exe

using Microsoft.InfoCards.Diagnostics;
using System;
using System.Diagnostics;
using System.IO;
using System.Security.Cryptography;
using System.Security.Principal;

namespace Microsoft.InfoCards
{
  internal class SymmetricCryptoSession : CryptoSession
  {
    private SymmetricAlgorithm m_alg;

    public SymmetricCryptoSession(
      Process process,
      DateTime expiration,
      WindowsIdentity identity,
      byte[] key)
      : base(process, expiration, identity, (object) key, CryptoSession.SessionType.Symmetric)
    {
      this.m_alg = (SymmetricAlgorithm) new RijndaelManaged();
      this.m_alg.Key = key;
    }

    protected override void OnDispose()
    {
      this.m_alg.Clear();
      this.m_alg.Dispose();
      this.m_alg = (SymmetricAlgorithm) null;
    }

    protected override void OnWrite(BinaryWriter bwriter)
    {
      bwriter.Write(this.m_alg.KeySize);
      bwriter.Write(this.m_alg.BlockSize);
      bwriter.Write(this.m_alg.FeedbackSize);
    }

    public byte[] GenerateDerivedKey(
      string algorithmUri,
      byte[] label,
      byte[] nonce,
      int derivedKeyLength,
      int offset)
    {
      if (algorithmUri == "http://schemas.xmlsoap.org/ws/2005/02/sc/dk/p_sha1" || algorithmUri == "http://docs.oasis-open.org/ws-sx/ws-secureconversation/200512/dk/p_sha1")
        return new Psha1DerivedKeyGenerator(this.m_alg.Key).GenerateDerivedKey(label, nonce, derivedKeyLength, offset);
      throw InfoCardTrace.ThrowHelperWarning((Exception) new InfoCardArgumentException(SR.GetString("ServiceUnsupportedKeyDerivationAlgorithm", (object) algorithmUri)));
    }

    public TransformCryptoSession GetCryptoTransform(
      CipherMode mode,
      PaddingMode padding,
      int feedbackSize,
      SymmetricCryptoSession.Direction direction,
      byte[] iv)
    {
      this.m_alg.Mode = mode;
      this.m_alg.Padding = padding;
      this.m_alg.IV = iv;
      return new TransformCryptoSession(this.ProcessObj, this.Expiration, this.Identity, SymmetricCryptoSession.Direction.Encrypt != direction ? this.m_alg.CreateDecryptor() : this.m_alg.CreateEncryptor());
    }

    public HashCryptoSession GetKeyedHash()
    {
      KeyedHashAlgorithm hash = (KeyedHashAlgorithm) new HMACSHA1(this.m_alg.Key);
      hash.Initialize();
      return new HashCryptoSession(this.ProcessObj, this.Expiration, this.Identity, hash);
    }

    public enum Direction
    {
      Encrypt = 1,
      Decrypt = 2,
    }
  }
}