https://github.com/c272/sharprsa
An RSA implementation in pure C#, using the BigInt class.
https://github.com/c272/sharprsa
bigint csharp encryption rsa rsa-cryptography
Last synced: 11 months ago
JSON representation
An RSA implementation in pure C#, using the BigInt class.
- Host: GitHub
- URL: https://github.com/c272/sharprsa
- Owner: c272
- Created: 2019-01-21T11:22:20.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2022-08-08T14:57:43.000Z (almost 4 years ago)
- Last Synced: 2023-03-06T08:06:57.129Z (over 3 years ago)
- Topics: bigint, csharp, encryption, rsa, rsa-cryptography
- Language: C#
- Homepage:
- Size: 47.9 KB
- Stars: 6
- Watchers: 1
- Forks: 3
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# SharpRSA
*An RSA implementation in pure C#, using the BigInt class.*
## Setup
To import SharpRSA, simply open the solution in VS2017 or above, and build. After this is done, add a reference to the generated class library and use the following to import:
```
using System;
using SharpRSA;
```
## Usage
The bindings of the class library are very simple, and are easy to understand. Below is an example of a few various use cases.
**Encrypt an Array of Bytes**
```
//The one parameter in this function is the bit length of the keys, which must be divisible by 8.
Keypair kp = RSA.GenerateKeyPair(1024);
byte[] raw = { 0x00, 0x01, 0x02, 0x03, 0x04 ... }
//These bytes are now encrypted using RSA, of the bitlength specified before.
byte[] encrypted = RSA.EncryptBytes(raw, kp.public_);
byte[] decrypted = RSA.DecryptBytes(encrypted, kp.private_);
```
**Encrypt a Class Instance**
```
Keypair kp = RSA.GenerateKeyPair(1024);
ExampleClass example = new ExampleClass(1, 2, 3, 4 ...);
//The class instance is now encrypted with RSA.
LockedBytes encrypted = RSA.EncryptClass(example, kp.public_);
ExampleClass decrypted = RSA.DecryptClass(encrypted, kp.private_);
```
## Networking
You can send public keys and LockedBytes over WCF (Windows Communication Foundation) or other networked means, as it is set up as a DataContract object.
Private keys *cannot* be passed over, as they are set to private, readonly and are not part of the DataContract specified. This is to prevent incorrect asymmetric key usage.