-
Notifications
You must be signed in to change notification settings - Fork 6
/
CryptStream.cs
79 lines (67 loc) · 1.44 KB
/
CryptStream.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
using System;
using System.IO;
namespace Noxico
{
public class CryptStream : Stream
{
public virtual Stream BaseStream { get; private set; }
public CryptStream(Stream stream)
{
BaseStream = stream;
}
public override bool CanRead
{
get { return BaseStream.CanRead; }
}
public override bool CanSeek
{
get { return BaseStream.CanSeek; }
}
public override bool CanWrite
{
get { return BaseStream.CanWrite; }
}
public override void Flush()
{
BaseStream.Flush();
}
public override long Length
{
get { return BaseStream.Length; }
}
public override long Position
{
get
{
return BaseStream.Position;
}
set
{
BaseStream.Position = value;
}
}
public override int Read(byte[] buffer, int offset, int count)
{
var cb = new Byte[count];
var j = BaseStream.Read(cb, 0, count);
for (var i = 0; i < count; i++)
buffer[i + offset] = (byte)(cb[i] ^ 0x80);
return j;
}
public override long Seek(long offset, SeekOrigin origin)
{
return BaseStream.Seek(offset, origin);
}
public override void SetLength(long value)
{
BaseStream.SetLength(value);
}
public override void Write(byte[] buffer, int offset, int count)
{
var cb = new byte[count];
for (int i = 0; i < count; i++)
cb[i] = (byte)(buffer[i + offset] ^ 0x80);
BaseStream.Write(cb, 0, count);
}
}
}