/// <summary> /// Metodo que genera llaves publica y privada del algoritmo RSA /// </summary> /// <returns>Modelo con informacion de llaves generadas</returns> private RSAModel GenerateOwnkeyEncrypts(string partnerKeys, string pathPublicKey) { int keySize = FileWriter.parameters.Value.KeyRSASize; CspParameters cp = new CspParameters(); RSAModel rsaModel = new RSAModel(); try { cp.KeyContainerName = "OwnkeyEncrypts" + partnerKeys; RSACryptoServiceProvider cryptoServiceProvider = new RSACryptoServiceProvider(keySize, cp); FileWriter.WriteOnEvents(EventLevel.Info, "Inicio proceso de creacion de llaves."); RSAParameters publicKey = cryptoServiceProvider.ExportParameters(false); //RSAParameters privateKey = cryptoServiceProvider.ExportParameters(true); //string publicKey = cryptoServiceProvider.ToXmlString(false); FileWriter.WriteOnEvents(EventLevel.Info, "Proceso de creacion de llaves RSA exitoso."); string publicKeyString = GetStringFromKey(publicKey, pathPublicKey); //string privateKeyString = GetStringFromKey(privateKey); rsaModel.PublicKey = publicKeyString; } catch (System.Exception ex) { FileWriter.WriteOnEvents(EventLevel.Exception, "Error generando llaves RSA. " + ex.Message); } return(rsaModel); }
public void GenerateNewRSA(int bitSize) { UiServices.SetBusyState(); RSAModel = new RSAModel(bitSize); Paragraph paragraph = new Paragraph(); paragraph.Inlines.Add(new Bold(new Underline(new Run("** " + Languages.buttonGenerateNewCryptosystem + " **\r\n")))); paragraph.Inlines.Add(new Bold(new Run(Languages.labelPrimeP))); paragraph.Inlines.Add(" " + PrimP + "\r\n"); paragraph.Inlines.Add(new Bold(new Run(Languages.labelPrimeQ))); paragraph.Inlines.Add(" " + PrimQ + "\r\n"); paragraph.Inlines.Add(new Bold(new Run(Languages.labelModulus))); paragraph.Inlines.Add(" " + ModulusN + "\r\n"); paragraph.Inlines.Add(new Bold(new Run(Languages.labelPrivateExponentD))); paragraph.Inlines.Add(" " + ExpD + "\r\n"); paragraph.Inlines.Add(new Bold(new Run(Languages.labelPublicExponentE))); paragraph.Inlines.Add(" " + ExpE + "\r\n"); if (History.Document.Blocks.FirstBlock != null) { History.Document.Blocks.InsertBefore(History.Document.Blocks.FirstBlock, paragraph); } else { History.Document.Blocks.Add(paragraph); } NotifyPropertyChanged("PrimP"); NotifyPropertyChanged("PrimQ"); NotifyPropertyChanged("ModulusN"); NotifyPropertyChanged("ExpD"); NotifyPropertyChanged("ExpE"); NotifyPropertyChanged("ValidationInfo"); }
///Generation RSA Keys public string GeneratePubPrivKeys(string partnerKeys, string publicKeyFile) { RSAModel rsaModel = new RSAModel(); FileWriter.WriteOnEvents(EventLevel.Info, "Verificando la existencia de la llave a generar."); if (KeysPartnerExists(partnerKeys, publicKeyFile)) { DeleteKeysPartner(partnerKeys); } rsaModel = GenerateOwnkeyEncrypts(partnerKeys, publicKeyFile); return(rsaModel.PublicKey); }
public void Cryptanalysis() { UiServices.SetBusyState(); Paragraph paragraph = new Paragraph(); try { paragraph.Inlines.Add(new Bold(new Underline(new Run("** " + Languages.buttonCryptanalysis + " **\r\n")))); paragraph.Inlines.Add(new Bold(new Run(Languages.labelCiphertext))); paragraph.Inlines.Add(" " + Cipher + "\r\n"); paragraph.Inlines.Add(new Bold(new Run(Languages.labelKnownPlainText))); paragraph.Inlines.Add(" " + KnownMessage + "\r\n"); string left = message.Substring(0, unknownStart); string right = message.Substring(unknownStart + unknownLength); UnknownMessageResult = RSAModel.StereotypedAttack(left, right, unknownLength, cipher, "4"); paragraph.Inlines.Add(new Bold(new Run(Languages.labelResultUnknownPlainText))); paragraph.Inlines.Add(" " + UnknownMessageResult + "\r\n"); } catch (Exception ex) { UnknownMessageResult = ""; paragraph.Inlines.Add(new Bold(new Run(Languages.labelAbort))); paragraph.Inlines.Add(" " + ex.Message + "\r\n"); MessageBox.Show(ex.Message, Languages.error, MessageBoxButton.OK, MessageBoxImage.Error); } finally { if (History.Document.Blocks.FirstBlock != null) { History.Document.Blocks.InsertBefore(History.Document.Blocks.FirstBlock, paragraph); } else { History.Document.Blocks.Add(paragraph); } } }
public void Decrypt() { UiServices.SetBusyState(); Message = RSAModel.Decrypt(cipher); Paragraph paragraph = new Paragraph(); paragraph.Inlines.Add(new Bold(new Underline(new Run("** " + Languages.buttonDecrypt + " **\r\n")))); paragraph.Inlines.Add(new Bold(new Run(Languages.labelCiphertext))); paragraph.Inlines.Add(" " + Cipher + "\r\n"); paragraph.Inlines.Add(new Bold(new Run(Languages.labelPlainText))); paragraph.Inlines.Add(" " + Message + "\r\n"); if (History.Document.Blocks.FirstBlock != null) { History.Document.Blocks.InsertBefore(History.Document.Blocks.FirstBlock, paragraph); } else { History.Document.Blocks.Add(paragraph); } NotifyPropertyChanged("Message"); }