예제 #1
0
        public static (string encryptedValue, Key publicKey, Key secretKey) EncryptString(string firstPrime, string secondPrime, string str)
        {
            var(publicKey, secretKey) = RSAKeysGenerator.GetKeys(firstPrime, secondPrime);
            var data      = Encoding.ASCII.GetBytes(str ?? string.Empty).Select(x => (int)x).ToArray();
            var encrypted = Encrypt(data, publicKey.Exponent, publicKey.Module);

            return(string.Join(":", encrypted), publicKey, secretKey);
        }
예제 #2
0
        public static (string newPath, Key publicKey, Key secretKey) EncryptFile(string path, string firstPrime, string secondPrime)
        {
            if (!File.Exists(path))
            {
                throw new FileNotFoundException("File does not exist.");
            }

            var file = File.ReadLines(path);

            var(publicKey, secretKey) = RSAKeysGenerator.GetKeys(firstPrime, secondPrime);
            var encrypted =
                file.Select(x => Encoding.ASCII.GetBytes(x).Select(b => (int)b))
                .Select(x => string.Join(":", Encrypt(x, publicKey.Exponent, publicKey.Module)));

            File.WriteAllLines(path + ".enc", encrypted);
            return(path + ".enc", publicKey, secretKey);
        }