private static void EmitDSmallerThanN(int keySize) { for (var i = 0; i < 10 * 256; ++i) { var csp = new RSACryptoServiceProvider(keySize); var rsaParams = csp.ExportParameters(true); csp.Dispose(); var key = new JsonWebKey(rsaParams); key.CanonicalizeRSA(); if (key.D.Length < key.N.Length) { EmitVariable("D_smallerThan_N", keySize, key); return; } } throw new Exception("Unable to generate key with D < N."); }
private static void EmitOrdinary(int keySize) { for (var i = 0; i < 10 * 256; ++i) { var csp = new RSACryptoServiceProvider(keySize); var rsaParams = csp.ExportParameters(true); csp.Dispose(); var key = new JsonWebKey(rsaParams); key.CanonicalizeRSA(); if (rsaParams.D.Length == rsaParams.Modulus.Length) { EmitVariable("ordinary", keySize, key); return; } } throw new Exception("Unable to generate ordinary key."); }