public void Generate1() { var p = CreateNumber(229, 13); // 3557 var q = CreateNumber(19, 10); // 2579 var e = CreateNumber(3); var key = gener.Generate(p, q, e); // Check Up CheckNumber(key.PublicKey.E, 3); CheckNumber(key.PublicKey.N, 255, 249, 139); // 9173503 CheckNumber(key.PrivateKey.D, 91, 65, 93); // 6111579 CheckNumber(key.PrivateKey.N, 255, 249, 139); // 9173503 }
public void EncryptDecrypt_R2048_JSON_Test() { var key = RsaKeyGenerator.Generate(AsymmetricKeyMode.Both, RsaKeySize.L2048, RsaKeyFormat.JSON); var function = RsaFactory.Create(key); #if NET451 || NET452 var cipherVal = function.EncryptByPublicKey("image", true); var originVal = function.DecryptByPrivateKey(cipherVal.CipherData, true); #else var cipherVal = function.EncryptByPublicKey("image", RSAEncryptionPadding.OaepSHA1); var originVal = function.DecryptByPrivateKey(cipherVal.CipherData, RSAEncryptionPadding.OaepSHA1); #endif Assert.Equal("image", originVal.GetOriginalDataDescriptor().GetString()); }
/// <summary> /// Генерирует ключи RSA /// </summary> /// <param name="length">длина n в битах</param> /// <param name="e"></param> public RsaKey Generate(int length, BigNumber e) { if (length < 1) { throw new ArgumentOutOfRangeException("length", length, @"length < 1"); } Status = ProcessStatus.Processing; var pLength = GetRandomLength(length); var qLength = Math.Max(1, length / 8 - pLength); var p = primeGener.Generate(pLength); var q = primeGener.Generate(qLength); var rsaKey = rsaGener.Generate(p, q, e); Status = ProcessStatus.Complete; return(rsaKey); }
/// <summary> /// Generate RSA key. /// </summary> /// <param name="mode"></param> /// <param name="keySize"></param> /// <param name="keyFormat"></param> /// <param name="keepingFormat"></param> /// <returns></returns> public static RsaKey GenerateKey(AsymmetricKeyMode mode, RsaKeySize keySize, RsaKeyFormat keyFormat = RsaKeyFormat.XML, bool keepingFormat = false) => RsaKeyGenerator.Generate(mode, keySize, keyFormat, keepingFormat);