Skip to content

Latest commit

 

History

History
30 lines (25 loc) · 1.19 KB

File metadata and controls

30 lines (25 loc) · 1.19 KB

Public Private Key Encryption Example

Simple working example of public private key encryption

References

Useful code

Creating the public and private key

int p = 17; // 1st large prime (larger)
int q = 13; // 2nd large prime
int pubKey1 = p*q;
int pubKey2 = 11;// < pubKey1 - 65537 is commonly used
int privKey = CalculateExtendedEuclideanAlgorithm(pubKey2, (p - 1) * (q - 1));

Encryption

var cipherText = BigInteger.Pow(input, pubKey2) % pubKey1;

Decryption

var plainText = (char)(BigInteger.Pow(cipherText, privKey) % pubKey1);