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; } }
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; } }
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; } }