Exemplo n.º 1
0
Arquivo: Key.cs Projeto: iSvB/Crypto
 public static void Create(BigInteger p, BigInteger q, BigInteger publicExponent, 
     out Key publicKey, out Key privateKey)
 {
     var module = p * q;
     var phi = (p - 1) * (q - 1);
     if (publicExponent >= phi)
         throw new ArgumentException("Открытая экспонента должна быть меньше " +
             "значения функции Эйлера от модуля n.");
     publicKey = new Key(publicExponent, module);
     privateKey = new Key(ModularInverse(publicExponent, phi), module);
 }
Exemplo n.º 2
0
Arquivo: Key.cs Projeto: iSvB/Crypto
 public static void Create(int size, double probability, BigInteger publicExponent, 
     out Key publicKey, out Key privateKey)
 {
     BigInteger p, q;
     p = PrimeNumber.Create(size / 2, probability);
     q = PrimeNumber.Create(size - size / 2, probability);
     var module = p * q;
     // Для простого n: phi(n) = n-1. Мультипликативная.
     var phi = (p - 1) * (q - 1);
     if (publicExponent >= phi)
         throw new ArgumentException("Открытая экспонента должна быть меньше " +
             "значения функции Эйлера от модуля n.");
     publicKey = new Key(publicExponent, module);
     privateKey = new Key(ModularInverse(publicExponent, phi), module);
 }
Exemplo n.º 3
0
 public static byte[] Cipher(byte[] message, Key key)
 {
     return ModPow(new BigInteger(message), key.Module, key.Exponent).ToByteArray();
 }