Ejemplo n.º 1
0
 public void Decrypt()
 {
     try
     {
         if (m_vType == 10101)
         {
             var cipherText = m_vData;
             Client.CPublicKey = cipherText.Take(32).ToArray();
             Blake.Init();
             Blake.Update(Client.CPublicKey);
             Blake.Update(Key.Crypto.PublicKey);
             var tmpNonce = Blake.Finish();
             Client.CRNonce = Client.GenerateSessionKey();
             var PlainText = CustomNaCl.OpenPublicBox(cipherText.Skip(32).ToArray(), tmpNonce, Key.Crypto.PrivateKey, Client.CPublicKey);
             Client.CSharedKey  = Client.CPublicKey;
             Client.CSessionKey = PlainText.Take(24).ToArray();
             Client.CSNonce     = PlainText.Skip(24).Take(24).ToArray();
             SetData(PlainText.Skip(48).ToArray());
         }
         else if (m_vType != 10100)
         {
             Client.CSNonce.Increment();
             SetData(CustomNaCl.OpenSecretBox(new byte[16].Concat(m_vData).ToArray(), Client.CSNonce, Client.CSharedKey));
         }
     }
     catch (Exception ex)
     {
         Client.CState = 0;
     }
 }
Ejemplo n.º 2
0
 public void Encrypt(byte[] plainText)
 {
     try
     {
         if (GetMessageType() == 20104 || GetMessageType() == 20103)
         {
             Blake.Init();
             Blake.Update(Client.CSNonce);
             Blake.Update(Client.CPublicKey);
             Blake.Update(Key.Crypto.PublicKey);
             var tmpNonce = Blake.Finish();
             plainText = Client.CRNonce.Concat(Client.CSharedKey).Concat(plainText).ToArray();
             SetData(CustomNaCl.CreatePublicBox(plainText, tmpNonce, Key.Crypto.PrivateKey, Client.CPublicKey));
             if (GetMessageType() == 20104)
             {
                 Client.CState = 2;
             }
         }
         else
         {
             Client.CRNonce.Increment();
             SetData(CustomNaCl.CreateSecretBox(plainText, Client.CRNonce, Client.CSharedKey).Skip(16).ToArray());
         }
     }
     catch (Exception ex)
     {
         Client.CState = 0;
     }
 }
Ejemplo n.º 3
0
 public void Decrypt()
 {
     try
     {
         if (m_vType == 10101)
         {
             byte[] cipherText = m_vData;
             Client.CPublicKey = cipherText.Take(32).ToArray();
             Hasher b = Blake2B.Create(new Blake2BConfig
             {
                 OutputSizeInBytes = 24
             });
             b.Init();
             b.Update(Client.CPublicKey);
             b.Update(Key.Crypto.PublicKey);
             Client.CRNonce     = b.Finish();
             cipherText         = CustomNaCl.OpenPublicBox(cipherText.Skip(32).ToArray(), Client.CRNonce, Key.Crypto.PrivateKey, Client.CPublicKey);
             Client.CSharedKey  = Client.CPublicKey;
             Client.CSessionKey = cipherText.Take(24).ToArray();
             Client.CSNonce     = cipherText.Skip(24).Take(24).ToArray();
             Client.CState      = 1;
             SetData(cipherText.Skip(48).ToArray());
         }
         else if (m_vType != 10100)
         {
             Client.CSNonce.Increment();
             SetData(CustomNaCl.OpenSecretBox(new byte[16].Concat(m_vData).ToArray(), Client.CSNonce, Client.CSharedKey));
         }
     }
     catch (Exception ex)
     {
         Client.CState = 0;
     }
 }
Ejemplo n.º 4
0
        public void Decrypt()
        {
            try
            {
                if (Constants.IsRc4)
                {
                    Client.Decrypt(m_vData);
                    if (m_vType == 10101)
                    {
                        Client.State = ClientState.Login;
                    }

                    // No need since the decryption occurs on same buffer.
                    //SetData(m_vData);
                }
                else
                {
                    if (m_vType == 10101)
                    {
                        var cipherText = m_vData;
                        Client.CPublicKey = cipherText.Take(32).ToArray();

                        var blake = Blake2B.Create(new Blake2BConfig
                        {
                            OutputSizeInBytes = 24
                        });
                        blake.Init();
                        blake.Update(Client.CPublicKey);
                        blake.Update(Key.Crypto.PublicKey);

                        Client.CRNonce = blake.Finish();

                        cipherText = CustomNaCl.OpenPublicBox(cipherText.Skip(32).ToArray(), Client.CRNonce, Key.Crypto.PrivateKey, Client.CPublicKey);

                        Client.CSharedKey  = Client.CPublicKey;
                        Client.CSessionKey = cipherText.Take(24).ToArray();
                        Client.CSNonce     = cipherText.Skip(24).Take(24).ToArray();
                        Client.State       = ClientState.Login;

                        SetData(cipherText.Skip(48).ToArray());
                    }
                    else
                    {
                        if (m_vType != 10100)
                        {
                            if (Client.State == ClientState.LoginSuccess)
                            {
                                Client.CSNonce.Increment();
                                SetData(CustomNaCl.OpenSecretBox(new byte[16].Concat(m_vData).ToArray(), Client.CSNonce, Client.CSharedKey));
                            }
                        }
                    }
                }
            }
            catch
            {
                Client.State = ClientState.Exception;
                throw;
            }
        }
Ejemplo n.º 5
0
 public void Encrypt(byte[] plainText)
 {
     try
     {
         if (GetMessageType() == 20104 || GetMessageType() == 20103)
         {
             Hasher b = Blake2B.Create(new Blake2BConfig
             {
                 OutputSizeInBytes = 24
             });
             b.Init();
             b.Update(Client.CSNonce);
             b.Update(Client.CPublicKey);
             b.Update(Key.Crypto.PublicKey);
             SetData(CustomNaCl.CreatePublicBox(Client.CRNonce.Concat(Client.CSharedKey).Concat(plainText).ToArray(), b.Finish(), Key.Crypto.PrivateKey, Client.CPublicKey));
             if (GetMessageType() == 20104)
             {
                 Client.CState = 2;
             }
         }
         else
         {
             Client.CRNonce.Increment();
             SetData(CustomNaCl.CreateSecretBox(plainText, Client.CRNonce, Client.CSharedKey).Skip(16).ToArray());
         }
     }
     catch (Exception)
     {
         Client.CState = 0;
     }
 }
Ejemplo n.º 6
0
        public void Encrypt(byte[] plainText)
        {
            try
            {
                if (Constants.IsRc4)
                {
                    Client.Encrypt(plainText);
                    if (m_vType == 20104)
                    {
                        Client.State = Client.ClientState.LoginSuccess;
                    }

                    SetData(plainText);
                }
                else
                {
                    if (m_vType == 20104 || m_vType == 20103)
                    {
                        Hasher b = Blake2B.Create(new Blake2BConfig
                        {
                            OutputSizeInBytes = 24
                        });
                        b.Init();
                        b.Update(Client.CSNonce);
                        b.Update(Client.CPublicKey);
                        b.Update(Key.Crypto.PublicKey);
                        SetData(CustomNaCl.CreatePublicBox(Client.CRNonce.Concat(Client.CSharedKey).Concat(plainText).ToArray(), b.Finish(), Key.Crypto.PrivateKey, Client.CPublicKey));
                        if (m_vType == 20104)
                        {
                            Client.State = Client.ClientState.LoginSuccess;
                        }
                    }
                    else
                    {
                        Client.CRNonce.Increment();
                        SetData(CustomNaCl.CreateSecretBox(plainText, Client.CRNonce, Client.CSharedKey).Skip(16).ToArray());
                    }
                }
            }
            catch (Exception)
            {
                Client.State = ClientState.Exception;
            }
        }