Exemple #1
0
        public static string Decrypt(BigInteger message, RSAKey key)
        {
            var bi = BigInteger.ModPow(message, key.KeyOne, key.KeyTwo);

            string output = Encoding.UTF8.GetString(bi.ToByteArray());

            return(output);
        }
Exemple #2
0
        public static string Decrypt(List <BigInteger> message, RSAKey key)
        {
            string decrypted = "";

            foreach (var item in message)
            {
                decrypted += Decrypt(item, key);
            }
            return(decrypted);
        }
Exemple #3
0
        public RSAProvider(KeySize size)
        {
            keySize = size;
            number1 = InitializeRandom();
            number2 = InitializeRandom();

            composition = number1 * number2;
            eulerFunc   = (number1 - 1) * (number2 - 1);

            publicExhibitor  = GetPublicExhibitor();
            privateExhibitor = GetPrivateExhibitor();
            PublicKey        = new RSAKey(publicExhibitor, composition);
            PrivateKey       = new RSAKey(privateExhibitor, composition);
            //SessionKey = InitializeRandom();
        }
Exemple #4
0
        public static List <string> Encrypt2(string message, RSAKey key)
        {
            List <string> res       = new List <string>();
            var           keyLength = key.KeyTwo.ToByteArray().Length;
            var           limit     = keyLength / 8;

            if (message.Length > limit)
            {
                var iterations = System.Math.Ceiling((float)message.Length / (float)(limit));
                for (int i = 0; i < iterations; i++)
                {
                    var t = new string(message.Skip(i * (limit)).Take((limit)).ToArray());
                    res.Add(Encrypt(t, key).ToString());
                }
            }
            else
            {
                res.Add(Encrypt(message, key).ToString());
            }
            return(res);
        }
Exemple #5
0
 private static BigInteger Encrypt(BigInteger message, RSAKey key)
 {
     return(BigInteger.ModPow(message, key.KeyOne, key.KeyTwo));
 }
Exemple #6
0
        public static BigInteger Encrypt(string message, RSAKey key)
        {
            BigInteger bi = new BigInteger(Encoding.UTF8.GetBytes(message));

            return(Encrypt(bi, key));
        }