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