Skip to content

Commit 42e1d48

Browse files
committed
Write README.md
1 parent faa1a1e commit 42e1d48

1 file changed

Lines changed: 26 additions & 1 deletion

File tree

README.md

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,26 @@
1-
# XTS.NET
1+
# XTS.NET
2+
A pure C# implementation of the XTS encryption mode, mostly used for disk encryption.
3+
4+
## How to use
5+
```csharp
6+
// Text generated with ChatGPT
7+
byte[] expectedPlaintext = Encoding.UTF8.GetBytes("In the serene dawn of a hidden valley, golden sunlight began filtering through the mist, painting the landscape in hues of orange and pink. Each leaf sparkled with a delicate sheen of dew, reminiscent of a thousand scattered jewels upon the gentle sway of early autumn trees. A distant river whispered a soft, calming lullaby, threading its way through a bed of smooth stones. Birds, waking from their slumber, chirped a subtle yet beautiful symphony that harmonized with the flowing water, creating a tranquil yet powerful soundscape. Amidst this quiet paradise, a lone figure walked, footprints left on the soft earth, exploring with reverent curiosity.\r\n\r\nAs the figure ventured deeper into the valley, an old stone bridge appeared over the river, its stones worn by countless seasons, yet resilient, standing as a testament to the artisans of old. Crossing the bridge, they were greeted by a vibrant grove, filled with the earthy scent of damp soil and the faint fragrance of blooming wildflowers. In this magical solitude, time seemed to slow, each step a moment to breathe, to feel, and to simply exist in harmony with the world around.\r\n\r\nThis should provide around 520 bytes for a few blocks but not perfectly divisible by 520, as requested. Let me know if you'd like more text or a different style.");
8+
byte[] key = [
9+
0xE1, 0x33, 0xCB, 0xCB, 0x9B, 0xA4, 0x9E, 0xCC,
10+
0x27, 0x40, 0xD6, 0xF9, 0x71, 0x22, 0xA9, 0x5A,
11+
0x0F, 0x70, 0x77, 0xAA, 0x20, 0x2E, 0xA9, 0xAE,
12+
0xB6, 0x4B, 0x3B, 0xDA, 0x87, 0xED, 0xE8, 0xC7
13+
];
14+
15+
Aes cipher = Aes.Create();
16+
17+
// The method encrypts in-place, so we clone the plaintext here
18+
byte[] ciphertext = (byte[])expectedPlaintext.Clone();
19+
cipher.EncryptXts(ciphertext, key, 0, 520);
20+
21+
Assert.That(ciphertext, Is.Not.EqualTo(expectedPlaintext));
22+
23+
cipher.DecryptXts(ciphertext, key, 0, 520);
24+
25+
Assert.That(ciphertext, Is.EqualTo(expectedPlaintext));
26+
```

0 commit comments

Comments
 (0)