public async Task <RSAKeyPair[]> GenerateKeyPairs(BigInteger p, BigInteger q) { BigInteger n = p * q; BigInteger pin = (p - 1) * (q - 1); var encryptKey = new RSAKeyPair(); var decryptKey = new RSAKeyPair(); encryptKey.number = decryptKey.number = n; encryptKey.value = await CalculateEncryptionKey(pin); decryptKey.value = await CalculateDecryptionKey(pin, encryptKey.value); return(new RSAKeyPair[] { encryptKey, decryptKey }); }
public async Task <IDictionary <byte, byte> > CreateByteMap(RSAKeyPair keyPair, IProgress <long> progress = null) { Dictionary <byte, byte> map = new Dictionary <byte, byte>(); for (int i = 0; i < 256; i++) { byte idx = Convert.ToByte(i); byte b = ConvertByte(ref keyPair, idx); map.Add(idx, b); if (i % 16 == 0) { progress?.Report(i); await Task.Delay(1); } } return(map); }
private byte ConvertByte(ref RSAKeyPair keyPair, byte b) => Convert.ToByte((int)(BaseEncrypter.Encrypt(keyPair, b) % Prime));
public BigInteger Encrypt(RSAKeyPair keyPair, BigInteger b) { return(BigInteger.ModPow(b, keyPair.value, keyPair.number)); }