public void ConstructorEmpty () { // under Mono:: a new key pair isn't generated RSAManaged rsa = new RSAManaged (); // test default key size Assert.AreEqual (1024, rsa.KeySize, "Default key size"); }
public override void GenerateClient (TlsContext ctx) { // Compute pre master secret using (var preMasterSecret = ctx.Session.GetSecureRandomBytes (48)) { preMasterSecret.Buffer [0] = (byte)((short)ctx.Configuration.RequestedProtocol >> 8); preMasterSecret.Buffer [1] = (byte)ctx.Configuration.RequestedProtocol; RSA rsa = null; // Create a new RSA key var serverCertificates = ctx.Session.PendingCrypto.ServerCertificates; if (serverCertificates == null || serverCertificates.Count == 0) { // FIXME: Should have received ServerKeyExchange message. throw new TlsException (AlertDescription.IlegalParameter); } else { rsa = new RSAManaged (serverCertificates [0].RSA.KeySize); rsa.ImportParameters (serverCertificates [0].RSA.ExportParameters (false)); } ComputeMasterSecret (ctx, preMasterSecret); // Encrypt premaster_sercret var formatter = new RSAPKCS1KeyExchangeFormatter (rsa); encryptedPreMasterSecret = formatter.CreateKeyExchange (preMasterSecret.Buffer); rsa.Clear (); } }
protected override void ProcessAsSsl3() { // Compute pre master secret byte[] preMasterSecret = this.Context.Cipher.CreatePremasterSecret(); // Create a new RSA key RSA rsa = null; if (this.Context.ServerSettings.ServerKeyExchange) { // this is the case for "exportable" ciphers rsa = new RSAManaged (); rsa.ImportParameters (this.Context.ServerSettings.RsaParameters); } else { rsa = this.Context.ServerSettings.CertificateRSA; } // Encrypt premaster_sercret RSAPKCS1KeyExchangeFormatter formatter = new RSAPKCS1KeyExchangeFormatter(rsa); // Write the preMasterSecret encrypted byte[] buffer = formatter.CreateKeyExchange(preMasterSecret); this.Write(buffer); // Create master secret this.Context.Cipher.ComputeMasterSecret(preMasterSecret); // Create keys this.Context.Cipher.ComputeKeys(); // Clear resources rsa.Clear(); }
static internal bool TryImportCapiPrivateKeyBlob(byte[] blob, int offset) { try { var rsap = GetParametersFromCapiPrivateKeyBlob(blob, offset); // Since we are only checking whether this throws an exception and // not actually returning the `RSA` object, we can use `RSAManaged` // here because that's what the `RSACryptoServiceProvider` implementation // does internally. var rsa = new RSAManaged(); rsa.ImportParameters(rsap); return(true); } catch (CryptographicException) { return(false); } }
public void Properties () { RSAManaged rsa = new RSAManaged (minKeySize); Assert.AreEqual (1, rsa.LegalKeySizes.Length, "LegalKeySize"); Assert.AreEqual (minKeySize, rsa.LegalKeySizes [0].MinSize, "LegalKeySize.MinSize"); Assert.AreEqual (16384, rsa.LegalKeySizes [0].MaxSize, "LegalKeySize.MaxSize"); Assert.AreEqual (8, rsa.LegalKeySizes [0].SkipSize, "LegalKeySize.SkipSize"); Assert.AreEqual ("RSA-PKCS1-KeyEx", rsa.KeyExchangeAlgorithm, "KeyExchangeAlgorithm"); Assert.AreEqual ("http://www.w3.org/2000/09/xmldsig#rsa-sha1", rsa.SignatureAlgorithm, "SignatureAlgorithm"); rsa.Clear (); Assert.AreEqual (1, rsa.LegalKeySizes.Length, "LegalKeySize(disposed)"); Assert.AreEqual (minKeySize, rsa.LegalKeySizes [0].MinSize, "LegalKeySize.MinSize(disposed)"); Assert.AreEqual (16384, rsa.LegalKeySizes [0].MaxSize, "LegalKeySize.MaxSize(disposed)"); Assert.AreEqual (8, rsa.LegalKeySizes [0].SkipSize, "LegalKeySize.SkipSize(disposed)"); Assert.AreEqual ("RSA-PKCS1-KeyEx", rsa.KeyExchangeAlgorithm, "KeyExchangeAlgorithm(disposed)"); Assert.AreEqual ("http://www.w3.org/2000/09/xmldsig#rsa-sha1", rsa.SignatureAlgorithm, "SignatureAlgorithm(disposed)"); }
/// <inheritdoc/> public ICryptographicKey ImportKeyPair(byte[] keyBlob, CryptographicPrivateKeyBlobType blobType = CryptographicPrivateKeyBlobType.Pkcs8RawPrivateKeyInfo) { Requires.NotNull(keyBlob, "keyBlob"); var parameters = KeyFormatter.GetFormatter(blobType).Read(keyBlob); Platform.RSA rsa; if (CapiKeyFormatter.IsCapiCompatible(parameters)) { rsa = new Platform.RSACryptoServiceProvider(); } else { #if DESKTOP rsa = new RSAManaged(); #else CapiKeyFormatter.VerifyCapiCompatibleParameters(parameters); throw new NotSupportedException(); #endif } rsa.ImportParameters(KeyFormatter.ToPlatformParameters(parameters)); return new RsaCryptographicKey(rsa, this.algorithm); }
public void TooBigKeyPair () { RSAManaged rsa = new RSAManaged (32768); }
private bool VerifyCounterSignature (PKCS7.SignerInfo cs, byte[] signature) { // SEQUENCE { // INTEGER 1 if (cs.Version != 1) return false; // SEQUENCE { // SEQUENCE { string contentType = null; ASN1 messageDigest = null; for (int i=0; i < cs.AuthenticatedAttributes.Count; i++) { // SEQUENCE { // OBJECT IDENTIFIER ASN1 attr = (ASN1) cs.AuthenticatedAttributes [i]; string oid = ASN1Convert.ToOid (attr[0]); switch (oid) { case "1.2.840.113549.1.9.3": // contentType contentType = ASN1Convert.ToOid (attr[1][0]); break; case "1.2.840.113549.1.9.4": // messageDigest messageDigest = attr[1][0]; break; case "1.2.840.113549.1.9.5": // SEQUENCE { // OBJECT IDENTIFIER // signingTime (1 2 840 113549 1 9 5) // SET { // UTCTime '030124013651Z' // } // } timestamp = ASN1Convert.ToDateTime (attr[1][0]); break; default: break; } } if (contentType != PKCS7.Oid.data) return false; // verify message digest if (messageDigest == null) return false; // TODO: must be read from the ASN.1 structure string hashName = null; switch (messageDigest.Length) { case 16: hashName = "MD5"; break; case 20: hashName = "SHA1"; break; } HashAlgorithm ha = HashAlgorithm.Create (hashName); if (!messageDigest.CompareValue (ha.ComputeHash (signature))) return false; // verify signature byte[] counterSignature = cs.Signature; // change to SET OF (not [0]) as per PKCS #7 1.5 ASN1 aa = new ASN1 (0x31); foreach (ASN1 a in cs.AuthenticatedAttributes) aa.Add (a); byte[] p7hash = ha.ComputeHash (aa.GetBytes ()); // we need to try all certificates string issuer = cs.IssuerName; byte[] serial = cs.SerialNumber; foreach (X509Certificate x509 in coll) { if (CompareIssuerSerial (issuer, serial, x509)) { if (x509.PublicKey.Length > counterSignature.Length) { RSACryptoServiceProvider rsa = (RSACryptoServiceProvider) x509.RSA; // we need to HACK around bad (PKCS#1 1.5) signatures made by Verisign Timestamp Service // and this means copying stuff into our own RSAManaged to get the required flexibility RSAManaged rsam = new RSAManaged (); rsam.ImportParameters (rsa.ExportParameters (false)); if (PKCS1.Verify_v15 (rsam, ha, p7hash, counterSignature, true)) { timestampChain.LoadCertificates (coll); return (timestampChain.Build (x509)); } } } } // no certificate can verify this signature! return false; }
[Test] // see bug #76627 public void MultipleKeys () { RSAManaged r384a = new RSAManaged (384); RSAManaged r384b = new RSAManaged (384); RSAManaged r512 = new RSAManaged (512); PKCS12 p12 = new PKCS12 (); Assert.AreEqual (0, p12.Keys.Count, "0"); p12.AddPkcs8ShroudedKeyBag (r512); Assert.AreEqual (1, p12.Keys.Count, "1"); p12.AddPkcs8ShroudedKeyBag (r384a); Assert.AreEqual (2, p12.Keys.Count, "2"); p12.AddPkcs8ShroudedKeyBag (r384b); Assert.AreEqual (3, p12.Keys.Count, "3"); }
void GenerateKeyPair () { var rsa = new RSAManaged ((int)keySize); KeyValue = rsa.ToXmlString (true); IsValid = true; }
/// <inheritdoc/> public ICryptographicKey ImportKeyPair(byte[] keyBlob, CryptographicPrivateKeyBlobType blobType = CryptographicPrivateKeyBlobType.Pkcs8RawPrivateKeyInfo) { Requires.NotNull(keyBlob, "keyBlob"); var parameters = KeyFormatter.GetFormatter(blobType).Read(keyBlob); if (!CapiKeyFormatter.IsCapiCompatible(parameters)) { // Try to make it CAPI compatible since it's faster on desktop, // and the only thing that could possibly work on wp8. RSAParameters adjustedParameters = KeyFormatter.NegotiateSizes(parameters); if (CapiKeyFormatter.IsCapiCompatible(adjustedParameters)) { parameters = adjustedParameters; } } Platform.RSA rsa; if (CapiKeyFormatter.IsCapiCompatible(parameters)) { rsa = new Platform.RSACryptoServiceProvider(); } else { #if DESKTOP rsa = new RSAManaged(); #else // Throw the exception explaining the problem. CapiKeyFormatter.VerifyCapiCompatibleParameters(parameters); // Make it obvious to the compiler that the buck stops here. // er... on the line above. throw new NotSupportedException(); #endif } rsa.ImportParameters(KeyFormatter.ToPlatformParameters(parameters)); return new RsaCryptographicKey(rsa, this.algorithm); }
private void Common (int dwKeySize, CspParameters p) { // Microsoft RSA CSP can do between 384 and 16384 bits keypair LegalKeySizesValue = new KeySizes [1]; LegalKeySizesValue [0] = new KeySizes (384, 16384, 8); base.KeySize = dwKeySize; rsa = new RSAManaged (KeySize); rsa.KeyGenerated += new RSAManaged.KeyGeneratedEventHandler (OnKeyGenerated); persistKey = (p != null); if (p == null) { p = new CspParameters (PROV_RSA_FULL); #if NET_1_1 if (useMachineKeyStore) p.Flags |= CspProviderFlags.UseMachineKeyStore; #endif store = new KeyPairPersistence (p); // no need to load - it cannot exists } else { store = new KeyPairPersistence (p); store.Load (); if (store.KeyValue != null) { persisted = true; this.FromXmlString (store.KeyValue); } } }
public void MonoXmlImportExportWithoutCRT () { RSAManaged rsa = new RSAManaged (); rsa.FromXmlString (MonoXml384woCRT); Assert.AreEqual (MonoXml384woCRT, rsa.ToXmlString (true), "Mono-Xml384-WithoutCRT"); rsa.FromXmlString (MonoXml448woCRT); Assert.AreEqual (MonoXml448woCRT, rsa.ToXmlString (true), "Mono-Xml448-WithoutCRT"); rsa.FromXmlString (MonoXml512woCRT); Assert.AreEqual (MonoXml512woCRT, rsa.ToXmlString (true), "Mono-Xml512-WithoutCRT"); rsa.FromXmlString (MonoXml576woCRT); Assert.AreEqual (MonoXml576woCRT, rsa.ToXmlString (true), "Mono-Xml576-WithoutCRT"); rsa.FromXmlString (MonoXml640woCRT); Assert.AreEqual (MonoXml640woCRT, rsa.ToXmlString (true), "Mono-Xml640-WithoutCRT"); rsa.FromXmlString (MonoXml704woCRT); Assert.AreEqual (MonoXml704woCRT, rsa.ToXmlString (true), "Mono-Xml704-WithoutCRT"); rsa.FromXmlString (MonoXml768woCRT); Assert.AreEqual (MonoXml768woCRT, rsa.ToXmlString (true), "Mono-Xml768-WithoutCRT"); rsa.FromXmlString (MonoXml832woCRT); Assert.AreEqual (MonoXml832woCRT, rsa.ToXmlString (true), "Mono-Xml832-WithoutCRT"); rsa.FromXmlString (MonoXml896woCRT); Assert.AreEqual (MonoXml896woCRT, rsa.ToXmlString (true), "Mono-Xml896-WithoutCRT"); rsa.FromXmlString (MonoXml960woCRT); Assert.AreEqual (MonoXml960woCRT, rsa.ToXmlString (true), "Mono-Xml960-WithoutCRT"); rsa.FromXmlString (MonoXml1024woCRT); Assert.AreEqual (MonoXml1024woCRT, rsa.ToXmlString (true), "Mono-Xml1024-WithoutCRT"); rsa.FromXmlString (MonoXml1536woCRT); Assert.AreEqual (MonoXml1536woCRT, rsa.ToXmlString (true), "Mono-Xml1536-WithoutCRT"); rsa.FromXmlString (MonoXml2048woCRT); Assert.AreEqual (MonoXml2048woCRT, rsa.ToXmlString (true), "Mono-Xml2048-WithoutCRT"); }
public void MonoXmlImportExport () { RSAManaged rsa = new RSAManaged (); rsa.FromXmlString (MonoXml384); Assert.AreEqual (MonoXml384, rsa.ToXmlString (true), "Mono-Xml384"); rsa.FromXmlString (MonoXml448); Assert.AreEqual (MonoXml448, rsa.ToXmlString (true), "Mono-Xml448"); rsa.FromXmlString (MonoXml512); Assert.AreEqual (MonoXml512, rsa.ToXmlString (true), "Mono-Xml512"); rsa.FromXmlString (MonoXml576); Assert.AreEqual (MonoXml576, rsa.ToXmlString (true), "Mono-Xml576"); rsa.FromXmlString (MonoXml640); Assert.AreEqual (MonoXml640, rsa.ToXmlString (true), "Mono-Xml640"); rsa.FromXmlString (MonoXml704); Assert.AreEqual (MonoXml704, rsa.ToXmlString (true), "Mono-Xml704"); rsa.FromXmlString (MonoXml768); Assert.AreEqual (MonoXml768, rsa.ToXmlString (true), "Mono-Xml768"); rsa.FromXmlString (MonoXml832); Assert.AreEqual (MonoXml832, rsa.ToXmlString (true), "Mono-Xml832"); rsa.FromXmlString (MonoXml896); Assert.AreEqual (MonoXml896, rsa.ToXmlString (true), "Mono-Xml896"); rsa.FromXmlString (MonoXml960); Assert.AreEqual (MonoXml960, rsa.ToXmlString (true), "Mono-Xml960"); rsa.FromXmlString (MonoXml1024); Assert.AreEqual (MonoXml1024, rsa.ToXmlString (true), "Mono-Xml1024"); rsa.FromXmlString (MonoXml1536); Assert.AreEqual (MonoXml1536, rsa.ToXmlString (true), "Mono-Xml1536"); rsa.FromXmlString (MonoXml2048); Assert.AreEqual (MonoXml2048, rsa.ToXmlString (true), "Mono-Xml2048"); }
public void CapiEncryptDecryptWithoutCRT () { RSAManaged rsa = new RSAManaged (); rsa.FromXmlString (CapiXml384woCRT); EncryptDecrypt ("Capi-384-WithoutCRT", rsa); rsa.FromXmlString (CapiXml448woCRT); EncryptDecrypt ("Capi-448-WithoutCRT", rsa); rsa.FromXmlString (CapiXml512woCRT); EncryptDecrypt ("Capi-512-WithoutCRT", rsa); rsa.FromXmlString (CapiXml576woCRT); EncryptDecrypt ("Capi-576-WithoutCRT", rsa); rsa.FromXmlString (CapiXml640woCRT); EncryptDecrypt ("Capi-640-WithoutCRT", rsa); rsa.FromXmlString (CapiXml704woCRT); EncryptDecrypt ("Capi-704-WithoutCRT", rsa); rsa.FromXmlString (CapiXml768woCRT); EncryptDecrypt ("Capi-768-WithoutCRT", rsa); rsa.FromXmlString (CapiXml832woCRT); EncryptDecrypt ("Capi-832-WithoutCRT", rsa); rsa.FromXmlString (CapiXml896woCRT); EncryptDecrypt ("Capi-896-WithoutCRT", rsa); rsa.FromXmlString (CapiXml960woCRT); EncryptDecrypt ("Capi-960-WithoutCRT", rsa); rsa.FromXmlString (CapiXml1024woCRT); EncryptDecrypt ("Capi-1024-WithoutCRT", rsa); rsa.FromXmlString (CapiXml1536woCRT); EncryptDecrypt ("Capi-1536-WithoutCRT", rsa); rsa.FromXmlString (CapiXml2048woCRT); EncryptDecrypt ("Capi-2048-WithoutCRT", rsa); }
public void CapiEncryptDecrypt () { RSAManaged rsa = new RSAManaged (); rsa.FromXmlString (CapiXml384); EncryptDecrypt ("Capi-384", rsa); rsa.FromXmlString (CapiXml448); EncryptDecrypt ("Capi-448", rsa); rsa.FromXmlString (CapiXml512); EncryptDecrypt ("Capi-512", rsa); rsa.FromXmlString (CapiXml576); EncryptDecrypt ("Capi-576", rsa); rsa.FromXmlString (CapiXml640); EncryptDecrypt ("Capi-640", rsa); rsa.FromXmlString (CapiXml704); EncryptDecrypt ("Capi-704", rsa); rsa.FromXmlString (CapiXml768); EncryptDecrypt ("Capi-768", rsa); rsa.FromXmlString (CapiXml832); EncryptDecrypt ("Capi-832", rsa); rsa.FromXmlString (CapiXml896); EncryptDecrypt ("Capi-896", rsa); rsa.FromXmlString (CapiXml960); EncryptDecrypt ("Capi-960", rsa); rsa.FromXmlString (CapiXml1024); EncryptDecrypt ("Capi-1024", rsa); rsa.FromXmlString (CapiXml1536); EncryptDecrypt ("Capi-1536", rsa); rsa.FromXmlString (CapiXml2048); EncryptDecrypt ("Capi-2048", rsa); }
private void EncryptDecrypt (string msg, RSAManaged rsa) { RSAParameters param = rsa.ExportParameters (false); byte[] data = { 0xFF, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 0x10, 0x11, 0x12, 0x13 }; // we don't need the private key to encrypt RSAManaged pubkey = new RSAManaged (); pubkey.ImportParameters (param); byte[] enc = pubkey.EncryptValue (data); byte[] dec = rsa.DecryptValue (enc); // note: the decrypted value is now right padded with zeros Assert.IsTrue (BitConverter.ToString (dec).EndsWith (BitConverter.ToString (data)), msg); }
private void Common (int dwKeySize, CspParameters p) { // Microsoft RSA CSP can do between 384 and 16384 bits keypair LegalKeySizesValue = new KeySizes [1]; LegalKeySizesValue [0] = new KeySizes (384, 16384, 8); base.KeySize = dwKeySize; rsa = new RSAManaged (KeySize); rsa.KeyGenerated += new RSAManaged.KeyGeneratedEventHandler (OnKeyGenerated); persistKey = (p != null); if (p == null) { p = new CspParameters (PROV_RSA_FULL); if (useMachineKeyStore) p.Flags |= CspProviderFlags.UseMachineKeyStore; store = new KeyPairPersistence (p); // no need to load - it cannot exists } else { store = new KeyPairPersistence (p); bool exists = store.Load (); bool required = (p.Flags & CspProviderFlags.UseExistingKey) != 0; if (required && !exists) throw new CryptographicException ("Keyset does not exist"); if (store.KeyValue != null) { persisted = true; this.FromXmlString (store.KeyValue); } } }
private void EncryptDecrypt (string msg, RSAManaged rsa) { RSAParameters param = rsa.ExportParameters (false); byte[] data = { 0xFF, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 0x10, 0x11, 0x12, 0x13 }; // we don't need the private key to encrypt RSAManaged pubkey = new RSAManaged (); pubkey.ImportParameters (param); byte[] enc = pubkey.EncryptValue (data); byte[] dec = rsa.DecryptValue (enc); Assert.AreEqual (BitConverter.ToString (data), BitConverter.ToString (dec), msg); }
private RSA getClientCertRSA(RSA privKey) { RSAParameters rsaParams = new RSAParameters(); RSAParameters privateParams = privKey.ExportParameters(true); // for RSA m_publickey contains 2 ASN.1 integers // the modulus and the public exponent ASN1 pubkey = new ASN1 (this.Context.ClientSettings.Certificates[0].GetPublicKey()); ASN1 modulus = pubkey [0]; if ((modulus == null) || (modulus.Tag != 0x02)) { return null; } ASN1 exponent = pubkey [1]; if (exponent.Tag != 0x02) { return null; } rsaParams.Modulus = this.getUnsignedBigInteger(modulus.Value); rsaParams.Exponent = exponent.Value; // Set private key parameters rsaParams.D = privateParams.D; rsaParams.DP = privateParams.DP; rsaParams.DQ = privateParams.DQ; rsaParams.InverseQ = privateParams.InverseQ; rsaParams.P = privateParams.P; rsaParams.Q = privateParams.Q; // BUG: MS BCL 1.0 can't import a key which // isn't the same size as the one present in // the container. int keySize = (rsaParams.Modulus.Length << 3); RSAManaged rsa = new RSAManaged(keySize); rsa.ImportParameters (rsaParams); return (RSA)rsa; }
public void MonoEncryptDecrypt () { RSAManaged rsa = new RSAManaged (); rsa.FromXmlString (MonoXml384); EncryptDecrypt ("Mono-384", rsa); rsa.FromXmlString (MonoXml448); EncryptDecrypt ("Mono-448", rsa); rsa.FromXmlString (MonoXml512); EncryptDecrypt ("Mono-512", rsa); rsa.FromXmlString (MonoXml576); EncryptDecrypt ("Mono-576", rsa); rsa.FromXmlString (MonoXml640); EncryptDecrypt ("Mono-640", rsa); rsa.FromXmlString (MonoXml704); EncryptDecrypt ("Mono-704", rsa); rsa.FromXmlString (MonoXml768); EncryptDecrypt ("Mono-768", rsa); rsa.FromXmlString (MonoXml832); EncryptDecrypt ("Mono-832", rsa); rsa.FromXmlString (MonoXml896); EncryptDecrypt ("Mono-896", rsa); rsa.FromXmlString (MonoXml960); EncryptDecrypt ("Mono-960", rsa); rsa.FromXmlString (MonoXml1024); EncryptDecrypt ("Mono-1024", rsa); rsa.FromXmlString (MonoXml1536); EncryptDecrypt ("Mono-1536", rsa); rsa.FromXmlString (MonoXml2048); EncryptDecrypt ("Mono-2048", rsa); }
public void MonoEncryptDecryptWithoutCRT () { RSAManaged rsa = new RSAManaged (); rsa.FromXmlString (MonoXml384woCRT); EncryptDecrypt ("Mono-384-WithoutCRT", rsa); rsa.FromXmlString (MonoXml448woCRT); EncryptDecrypt ("Mono-448-WithoutCRT", rsa); rsa.FromXmlString (MonoXml512woCRT); EncryptDecrypt ("Mono-512-WithoutCRT", rsa); rsa.FromXmlString (MonoXml576woCRT); EncryptDecrypt ("Mono-576-WithoutCRT", rsa); rsa.FromXmlString (MonoXml640woCRT); EncryptDecrypt ("Mono-640-WithoutCRT", rsa); rsa.FromXmlString (MonoXml704woCRT); EncryptDecrypt ("Mono-704-WithoutCRT", rsa); rsa.FromXmlString (MonoXml768woCRT); EncryptDecrypt ("Mono-768-WithoutCRT", rsa); rsa.FromXmlString (MonoXml832woCRT); EncryptDecrypt ("Mono-832-WithoutCRT", rsa); rsa.FromXmlString (MonoXml896woCRT); EncryptDecrypt ("Mono-896-WithoutCRT", rsa); rsa.FromXmlString (MonoXml960woCRT); EncryptDecrypt ("Mono-960-WithoutCRT", rsa); rsa.FromXmlString (MonoXml1024woCRT); EncryptDecrypt ("Mono-1024-WithoutCRT", rsa); rsa.FromXmlString (MonoXml1536woCRT); EncryptDecrypt ("Mono-1536-WithoutCRT", rsa); rsa.FromXmlString (MonoXml2048woCRT); EncryptDecrypt ("Mono-2048-WithoutCRT", rsa); }
public void ConstructorKeySize () { RSAManaged rsa = new RSAManaged (minKeySize); // test default key size Assert.AreEqual (minKeySize, rsa.KeySize, "Minimum key size"); }
public void RemoveKeyBag_Test () { PKCS12 p12 = new PKCS12 (); RSAManaged rsa = new RSAManaged (384); p12.AddKeyBag (rsa); Assert.AreEqual (1, p12.Keys.Count, "RK.1"); RSAManaged rsa2 = new RSAManaged (384); p12.RemoveKeyBag (rsa2); Assert.AreEqual (1, p12.Keys.Count, "RK.2"); p12.RemoveKeyBag (rsa); Assert.AreEqual (0, p12.Keys.Count, "RK.3"); }
public void Bug79269 () { RSAManaged rsa = new RSAManaged (); rsa.FromXmlString ("<RSAKeyValue><Modulus>iSObDmmhDgrl4NiLaviFcpv4NdysBWJcqiVz3AQbPdajtXaQQ8VJdfRkixah132yKOFGCWZhHS3EuPMh8dcNwGwta2nh+m2IV6ktzI4+mZ7CSNAsmlDY0JI+H8At1vKvNArlC5jkVGuliYroJeSU/NLPLNYgspi7TtXGy9Rfug8=</Modulus><Exponent>EQ==</Exponent></RSAKeyValue>"); Assert.IsTrue (rsa.PublicOnly, "PublicOnly"); string b64 = @"YgyAhscnTTIcDeLJTZcOYYyHVxNhV6d03jeZYjq0sPMEsfCCbE/NcFyYHD9BTuiduqPplCLbGpfZIZYJ6vAP9m5z4Q9eEw79kmEFCsm8wSKEo/gKiptVpwQ78VOPrWd/wEkTTeeg2nVim3JIsTKGFlV7rKxIWQhGN9aAqgP8nZI="; byte [] bytes = Convert.FromBase64String (b64); rsa.DecryptValue (bytes); }
public void UpdateCertificateRSA() { if (this.clientCertificate == null) { this.certificateRSA = null; } else { X509.X509Certificate cert = new X509.X509Certificate(this.clientCertificate.GetRawCertData()); this.certificateRSA = new RSAManaged( cert.RSA.KeySize); this.certificateRSA.ImportParameters( cert.RSA.ExportParameters(false)); } }
public void Bug18482 () { RSAManaged privateRsa = new RSAManaged (); privateRsa.FromXmlString (MonoXml384); var rsaParameters = privateRsa.ExportParameters (false); RSAManaged publicRsa = new RSAManaged (); //Generates a key pair with private key values publicRsa.ExportParameters (false); //Sets public key values and should reset private key values publicRsa.ImportParameters (rsaParameters); //Should export valid parameters without throwing an exception. publicRsa.ExportParameters (false); }
void Common (int dwKeySize, bool parameters) { // Microsoft RSA CSP can do between 384 and 16384 bits keypair LegalKeySizesValue = new KeySizes [1]; LegalKeySizesValue [0] = new KeySizes (384, 16384, 8); base.KeySize = dwKeySize; rsa = new RSAManaged (KeySize); rsa.KeyGenerated += new RSAManaged.KeyGeneratedEventHandler (OnKeyGenerated); persistKey = parameters; if (parameters) return; // no need to load - it cannot exists var p = new CspParameters (PROV_RSA_FULL); if (useMachineKeyStore) p.Flags |= CspProviderFlags.UseMachineKeyStore; store = new KeyPairPersistence (p); }
public void TooSmallKeyPair () { RSAManaged rsa = new RSAManaged (256); }
public void FixtureSetUp () { rsa = new RSAManaged (); rsa.FromXmlString (rsaxml); }
public void FixtureSetup () { key = new RSAManaged (384); }