// Collection of code snippets by Arne Vajhøj // (likely posted to comp.os.vms/INFO-VAX, INFO-TPU, MACRO32, eksperten.dk, newz.dk, LinkedIn or other place sometime between 1990 and now) using System; using System.Text; using Org.BouncyCastle.Crypto.Engines; using Org.BouncyCastle.Crypto.Paddings; using Org.BouncyCastle.Crypto.Parameters; namespace E { public class MainClass { public static void Main(string[] args) { string key = "hemmelig"; String plaindata1 = "Dette er en lille test af pustefisken !"; Console.WriteLine(plaindata1); byte[] cipherbuf = new byte[100]; PaddedBufferedBlockCipher bfeng = new PaddedBufferedBlockCipher(new BlowfishEngine()); bfeng.Init(true, new KeyParameter(Encoding.Default.GetBytes(key))); int ncipher = bfeng.ProcessBytes(Encoding.Default.GetBytes(plaindata1), 0, plaindata1.Length, cipherbuf, 0); ncipher += bfeng.DoFinal(cipherbuf, ncipher); for(int i = 0; i < ncipher; i++) { Console.Write(" " + cipherbuf[i]); } Console.WriteLine(); byte[] plainbuf = new byte[100]; bfeng.Init(false, new KeyParameter(Encoding.Default.GetBytes(key))); int nplain = bfeng.ProcessBytes(cipherbuf, 0, ncipher, plainbuf, 0); nplain += bfeng.DoFinal(plainbuf, nplain); string plaindata2 = Encoding.Default.GetString(plainbuf, 0, nplain); Console.WriteLine(plaindata2); } } }