XtsStream Class
Namespace: Rebex.Security
Assembly: Rebex.Security.dll (version 8.0.9673)
Implements XTS-AES, a standard algorithm for protection of stored data defined by IEEE P1619.
Syntax
public class XtsStream : Stream, IAsyncDisposable, IDisposable
Inherited Members
Examples
See https://www.rebex.net/security.net/features/xts-aes.aspx for more code snippets.
See https://www.rebex.net/security.net/samples.aspx for ready-to-use samples.
Encrypting data
// open a file stream
var fs = File.Open(@"C:\MyData\data.xts", FileMode.OpenOrCreate);
// prepare settings to use SHA-256 (default is SHA-1)
var settings = new XtsSettings() { HashingAlgorithm = HashingAlgorithmId.SHA256 };
// create XTS-AES stream on top of the file stream to add encryption
var xts = new Rebex.Security.XtsStream(fs, "password", settings);
// use the XTS-AES stream just like you would use the file stream
using (var writer = new StreamWriter(xts))
{
writer.WriteLine("This is a secret text.");
writer.WriteLine("Encrypted by Rebex XTS-AES stream.");
writer.Flush();
}
Decrypting data
// prepare settings to use SHA-256 (default is SHA-1)
var settings = new XtsSettings() { HashingAlgorithm = HashingAlgorithmId.SHA256 };
// create XTS-AES stream from encrypted file
var xts = new XtsStream(@"C:\MyData\data.xts", "password", settings);
// initialize reader from XTS-AES stream
var reader = new StreamReader(xts);
// decrypt data by reading
var decrypted = reader.ReadToEnd();
Console.WriteLine(decrypted);
Constructors
Fields
| Name | Description |
|---|---|
| DefaultBlockSize | Default block size (64 KB). |
Properties
| Name | Description |
|---|---|
| BlockSize | Gets a size of one XTS block in bytes |
| CanRead | Gets a value indicating whether the stream supports reading. |
| CanSeek | Gets a value indicating whether the stream supports seeking. |
| CanWrite | Gets a value indicating whether the stream supports writing. |
| Length | Gets the length in bytes of the stream. |
| Position | Gets or sets the position within the stream. |
Methods
| Name | Description |
|---|---|
| Dispose(Boolean) | Releases resources used by this stream. |
| Flush() | Clears all buffers for this stream and causes any buffered data to be written to the underlying device. |
| Read(Byte[], Int32, Int32) | Reads a sequence of bytes from the stream and advances the position within the stream by the number of bytes read. |
| Seek(Int64, SeekOrigin) | Sets the position within the stream. |
| SetLength(Int64) | Sets the length of the stream. |
| Write(Byte[], Int32, Int32) | Writes a sequence of bytes to the stream and advances the current position within this stream by the number of bytes written. |