private void BtnCrypt_Click_1(object sender, EventArgs e) { cryptedPic = mainPic; try { List <BigInteger> oneLineOfPixel = new List <BigInteger>(); for (int X = 0; X < cryptedPic.Width; X++) { for (int Y = 0; Y < cryptedPic.Height; Y++) { Color pixelColor = cryptedPic.GetPixel(X, Y); BigInteger.TryParse(pixelColor.ToArgb().ToString(), out BigInteger pixelToArgb); Color cryptedPixel = Color.FromArgb((int)(PreparedRSA.Crypt(pixelToArgb) % int.MaxValue)); oneLineOfPixel.Add(PreparedRSA.Crypt(pixelToArgb)); cryptedPic.SetPixel(X, Y, cryptedPixel); } mesPixels.Add(oneLineOfPixel); oneLineOfPixel = new List <BigInteger>(); } pictureBox1.Image = cryptedPic; ExportKeys(); ExportCryptedPicture(); } catch (DivideByZeroException error) { MessageBox.Show(error.Data + "\n" + error.Message + "\n" + error.Source, null, MessageBoxButtons.OK, MessageBoxIcon.Error); ChangeStatus("An error happened !", FlatUI.FlatAlertBox._Kind.Error); Application.Exit(); } ChangeStatus("Done with success!", FlatUI.FlatAlertBox._Kind.Success); }
public void StreamData(RemoteFileInfo rfi) { Stream stream = null; BinaryReader br = null; BinaryWriter bw = null; try { stream = rfi.stream; br = new BinaryReader(stream); bw = new BinaryWriter(File.Open(dir_path + rfi.FileName, FileMode.Create, FileAccess.Write, FileShare.None)); int buffer_size = 2048; byte[] buffer = new byte[buffer_size]; int bytesRead; while ((bytesRead = br.Read(buffer, 0, buffer.Length)) > 0) { if (bytesRead < buffer_size) { byte[] new_buffer = new byte[bytesRead]; Buffer.BlockCopy(buffer, 0, new_buffer, 0, bytesRead); bw.Write(rsa.Crypt(new_buffer)); } else { bw.Write(rsa.Crypt(buffer)); } } } catch { } finally { if (stream != null) { stream.Dispose(); stream.Close(); stream = null; } if (br != null) { br.Dispose(); br.Close(); br = null; } if (bw != null) { bw.Dispose(); bw.Close(); bw = null; } } }
private void flatButton1_Click(object sender, EventArgs e) { RSA myRSA = new RSA(); flatLabel8.Text = myRSA.getPrivateKey().ToString(); flatLabel9.Text = myRSA.getPublickey()[0] + " & " + myRSA.getPublickey()[1]; flatLabel6.Text = myRSA.Crypt(Convert.ToInt32(flatNumeric2.Value)).ToString(); lblD.Text = myRSA.Decrypt(Convert.ToInt32(flatLabel6.Text)).ToString(); }
public void RSASimpleTest() { var data = new BigInteger(123456).ToByteArray(); var(publicKey, privateKey) = RSAKeyGenerator.Generate(); var sign = RSA.Crypt(data, privateKey); var decryptedData = RSA.Crypt(sign, publicKey); data.Should().BeEquivalentTo(decryptedData, options => options.WithStrictOrdering()); }
public void RSAFunctionalTest() { var data = new byte[123456]; new Random().NextBytes(data); var hash = SHA512.GetHash(data); var(publicKey, privateKey) = RSAKeyGenerator.Generate(); var sign = RSA.Crypt(hash, privateKey); var decryptedHash = RSA.Crypt(sign, publicKey); hash.Should().BeEquivalentTo(decryptedHash, options => options.WithStrictOrdering()); }
public byte[] EncryptText(EncryptTextMessage message) { byte[] encryptedText = null; //Odradi se enkripcija if (message.Algorithm == AlgorithmType.RC4) { RC4 rc = new RC4(message.Key, message.IV); encryptedText = rc.Crypt(message.Data); } else if (message.Algorithm == AlgorithmType.RC4CTR) { RC4 rc = new RC4(message.Key, message.IV); encryptedText = rc.CryptWithCTR(message.Data); } else if (message.Algorithm == AlgorithmType.A52 || message.Algorithm == AlgorithmType.A52CTR) { A52 alg = new A52(); alg.SetKey(message.Key); alg.SetF(message.FKeyA52); if (message.Algorithm == AlgorithmType.A52) { encryptedText = alg.Crypt(message.Data); } else { alg.SetIV(message.IV); encryptedText = alg.CryptWithCTR(message.Data); } } else if (message.Algorithm == AlgorithmType.RSA) { RSA rsa = new RSA(); rsa.E = new BigInteger(message.Key); rsa.P = new BigInteger(message.P); rsa.Q = new BigInteger(message.Q); rsa.GenerateRSA(); //BigInteger result = rsa.Crypt(new BigInteger(message.Data)); //encryptedText = result.ToByteArray(); encryptedText = rsa.Crypt(message.Data); } else if (message.Algorithm == AlgorithmType.TigerHash) { TigerHash th = new TigerHash(); byte[] msg = message.Data; encryptedText = th.ComputeHash(message.Data); } return(encryptedText); }
private void CreateHauteurListAndCrypt(String path) { ChangeStatus("Crypting your sound ...", FlatUI.FlatAlertBox._Kind.Info); AudioFileReader ReadedSound = new AudioFileReader(path); int SoundSize = Convert.ToInt32(ReadedSound.Length); byte[] HauteurArray = new byte[SoundSize]; ReadedSound.Read(HauteurArray, 0, SoundSize); Hauteur = ReadedSound.WaveFormat.SampleRate; Channel = ReadedSound.WaveFormat.Channels; for (int a = 0; a < HauteurArray.Length; ++a) { HauteurArray[a] *= Multiplier; HauteurCryptees.Add(PreparedRSA.Crypt(HauteurArray[a])); } }
/////RSA --------------------------------------------------------- public byte[] RSACrypt(byte[] input) { // RSA rsa = new RSA(); // rsa.init(17, 23); return(rsa.Crypt(input)); }