Revision 0e1acc13 trunk/Pithos.Network/SHA1OpenSSL.cs
b/trunk/Pithos.Network/SHA1OpenSSL.cs | ||
---|---|---|
51 | 51 |
} |
52 | 52 |
} |
53 | 53 |
} |
54 |
|
|
55 |
public class SHA256OpenSSL : SHA256 |
|
56 |
{ |
|
57 |
|
|
58 |
private MessageDigestContext _context; |
|
59 |
|
|
60 |
public SHA256OpenSSL() |
|
61 |
{ |
|
62 |
_context = new MessageDigestContext(MessageDigest.CreateByName("SHA256")); |
|
63 |
_context.Init(); |
|
64 |
} |
|
65 |
|
|
66 |
public override void Initialize() |
|
67 |
{ |
|
68 |
_context.Init(); |
|
69 |
} |
|
70 |
|
|
71 |
protected override void HashCore(byte[] array, int ibStart, int cbSize) |
|
72 |
{ |
|
73 |
if (array.Length == cbSize) |
|
74 |
_context.Update(array); |
|
75 |
else |
|
76 |
{ |
|
77 |
var block = new byte[cbSize]; |
|
78 |
Buffer.BlockCopy(array, ibStart, block, 0, cbSize); |
|
79 |
_context.Update(block); |
|
80 |
} |
|
81 |
} |
|
82 |
|
|
83 |
protected override byte[] HashFinal() |
|
84 |
{ |
|
85 |
return _context.DigestFinal(); |
|
86 |
} |
|
87 |
|
|
88 |
protected override void Dispose(bool disposing) |
|
89 |
{ |
|
90 |
base.Dispose(disposing); |
|
91 |
if (disposing) |
|
92 |
{ |
|
93 |
if (_context != null) |
|
94 |
_context.Dispose(); |
|
95 |
_context = null; |
|
96 |
} |
|
97 |
} |
|
98 |
} |
|
54 | 99 |
} |
Also available in: Unified diff