public static DarkRiftReader DecryptReaderRSA(this DarkRiftReader reader, RSAParameters privateKey) { if (reader.Length > 256) { throw new ArgumentOutOfRangeException(nameof(reader), "reader mustn't contain more then 256 bytes"); } byte[] data = new byte[256]; for (int i = 0; i < 256; i++) { data[i] = reader.ReadByte(); } data = DecryptRSA(data, privateKey); DarkRiftWriter writer = DarkRiftWriter.Create(); writer.WriteRaw(data, 0, data.Length); Message message = Message.Create(0, writer); DarkRiftReader newReader = message.GetReader(); message.Dispose(); writer.Dispose(); reader.Dispose(); return(newReader); }
public static DarkRiftWriter EncryptWriterRSA(this DarkRiftWriter writer, RSAParameters publicKey) { Message message = Message.Create(0, writer); DarkRiftReader reader = message.GetReader(); byte[] data = reader.ReadRaw(reader.Length); data = EncryptRSA(data, publicKey); writer = DarkRiftWriter.Create(); writer.WriteRaw(data, 0, data.Length); message.Dispose(); reader.Dispose(); return(writer); }
public static DarkRiftWriter EncryptWriterAES(this DarkRiftWriter writer, byte[] key) { Message message = Message.Create(0, writer); DarkRiftReader reader = message.GetReader(); byte[] data = reader.ReadRaw(reader.Length); data = Encrypt_Aes(data, key); DarkRiftWriter _writer = DarkRiftWriter.Create(); _writer.WriteRaw(data, 0, data.Length); message.Dispose(); reader.Dispose(); return(_writer); }