Beispiel #1
0
        public async Task <string> Decrypt(BigInt.BigInt[] encrypt, PrivateKey privateKey, IProgress <double> progress = default)
        {
            var decrypted = new int[encrypt.Length];
            await Task.Run(() =>
            {
                for (var i = 0; i < encrypt.Length; i++)
                {
                    decrypted[i] = (byte)RsaEncrypting.DecryptNumber(encrypt[i], privateKey);
                    progress?.Report(Math.Round(100.0 / encrypt.Length *i));
                }

                progress?.Report(100);
            });

            return(StringUtils.ConvertNumbersToString(decrypted, _alphabet));
        }
Beispiel #2
0
        public async Task <BigInt.BigInt[]> Encrypt(string text, PublicKey publicKey, IProgress <double> progress = default)
        {
            var textBytes = StringUtils.ConvertToNumbers(text.ToLower(), _alphabet);
            var encrypted = new BigInt.BigInt[textBytes.Length];

            await Task.Run(() =>
            {
                for (var i = 0; i < textBytes.Length; i++)
                {
                    encrypted[i] = RsaEncrypting.EncryptNumber(textBytes[i], publicKey);
                    progress?.Report(100.0 / text.Length *i);
                }

                progress?.Report(100);
            });

            return(encrypted);
        }
Beispiel #3
0
 public void NumberDecryptionTest(int encrypted, int original) =>
 Assert.AreEqual(original, RsaEncrypting.DecryptNumber(encrypted, PrivateKey));
Beispiel #4
0
 public void NumberEncryptionTest(int number, int encrypted) =>
 Assert.AreEqual((BigInt.BigInt)encrypted, RsaEncrypting.EncryptNumber(number, PublicKey));