blob: 6dab4ae3322b54d314753fd4b66e610c8d28d4f6 (
plain) (
blame)
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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
|
using System;
using System.IO;
using Org.BouncyCastle.Crypto.Engines;
using Org.BouncyCastle.Crypto.Parameters;
using Org.BouncyCastle.Utilities;
namespace Org.BouncyCastle.Crypto
{
public class BufferedIesCipher
: BufferedCipherBase
{
private readonly IesEngine engine;
private bool forEncryption;
private MemoryStream buffer = new MemoryStream();
public BufferedIesCipher(
IesEngine engine)
{
if (engine == null)
throw new ArgumentNullException("engine");
this.engine = engine;
}
public override string AlgorithmName
{
// TODO Create IESEngine.AlgorithmName
get { return "IES"; }
}
public override void Init(
bool forEncryption,
ICipherParameters parameters)
{
this.forEncryption = forEncryption;
// TODO
throw Platform.CreateNotImplementedException("IES");
}
public override int GetBlockSize()
{
return 0;
}
public override int GetOutputSize(
int inputLen)
{
if (engine == null)
throw new InvalidOperationException("cipher not initialised");
int baseLen = inputLen + (int) buffer.Length;
return forEncryption
? baseLen + 20
: baseLen - 20;
}
public override int GetUpdateOutputSize(
int inputLen)
{
return 0;
}
public override byte[] ProcessByte(
byte input)
{
buffer.WriteByte(input);
return null;
}
public override byte[] ProcessBytes(
byte[] input,
int inOff,
int length)
{
if (input == null)
throw new ArgumentNullException("input");
if (inOff < 0)
throw new ArgumentException("inOff");
if (length < 0)
throw new ArgumentException("length");
if (inOff + length > input.Length)
throw new ArgumentException("invalid offset/length specified for input array");
buffer.Write(input, inOff, length);
return null;
}
public override byte[] DoFinal()
{
byte[] buf = buffer.ToArray();
Reset();
return engine.ProcessBlock(buf, 0, buf.Length);
}
public override byte[] DoFinal(
byte[] input,
int inOff,
int length)
{
ProcessBytes(input, inOff, length);
return DoFinal();
}
public override void Reset()
{
buffer.SetLength(0);
}
}
}
|