https://github.com/layer26/SecureStream
Provide CTR based simple AES encryption/decryption stream.
https://github.com/layer26/SecureStream
aes-256 aes-ctr csharp stream
Last synced: 7 days ago
JSON representation
Provide CTR based simple AES encryption/decryption stream.
- Host: GitHub
- URL: https://github.com/layer26/SecureStream
- Owner: 10sa
- License: mit
- Created: 2018-11-30T00:46:52.000Z (almost 7 years ago)
- Default Branch: master
- Last Pushed: 2019-05-11T01:29:07.000Z (over 6 years ago)
- Last Synced: 2024-11-19T22:55:16.471Z (11 months ago)
- Topics: aes-256, aes-ctr, csharp, stream
- Language: C#
- Homepage:
- Size: 41 KB
- Stars: 2
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# SecureStream
Provide CTR based simple AES encryption/decryption stream.# Using
## Basic methods
```csharp
// This method same as MemoryStream class methods. //
CryptoMemoryStream.Write
CryptoMemoryStream.Read
// Encrypts and writes bytes to the stream. //
CryptoMemoryStream.Encrypt
// Decrypts and reading bytes from stream. //
CryptoMemoryStream.Decrypt
```
## Notes ##
These methods do not reuse the nonce used in the CTR algorithm. That is, the result of encrypting all the bytes at once by the Write method differs from the result of encrypting the bytes by dividing them many times.## Encryption
```csharp
byte[] datas = new byte[] {0x00, 0x00, 0x00, 0x00};
byte[] buffer = new byte[datas.Length];
// Encrypt bytes //
CryptoMemoryStream.Encrypt(datas, 0, datas.Length);
// Reading encrypted bytes //
// The CTR-based AES encryption algorithm has the same length as the original data length and the encrypted data. //
// 0x00, 0x00, 0x00, 0x00 => 0x??, 0x??, 0x??, 0x??
CryptoMemoryStream.Read(buffer, 0, buffer.Length);
```## Decryption
```csharp
byte[] encryptedDatas = new byte[] {0x??, 0x??, 0x??, 0x??};
byte[] buffer = new byte[encryptedDatas.Length];
// Decrypt bytes //
CryptoMemoryStream.Write(encryptedDatas, 0, encryptedDatas.Length);
// Reading dencrypted bytes //
CryptoMemoryStream.Decrypt(buffer, 0, buffer.Length);
```