예제 #1
0
        public string decryptString(string encrypted)
        {
            byte[] iv        = getbytes("12345678");
            byte[] plain     = getbytes(encrypted);
            byte[] decrypted = new byte[plain.Length];
            Array.Clear(decrypted, 0, decrypted.Length);
            byte[]      key = getbytes("p1zz@p1zz@p1zz@p1zz@p1zz@p1zz@p1");
            BlowfishCBC bfc = new BlowfishCBC();

            bfc.IV = iv;
            bfc.Initialize(key, 0, key.Length);
            bfc.Decrypt(plain, 0, decrypted, 0, plain.Length);
            return(getstring(decrypted));
        }
예제 #2
0
    public static void TestBlowfishCBC()
    {
        String sDemo = "The Blowfish encryption algorithm was introduced in 1994.";

        System.Console.WriteLine(sDemo);

        byte[] ptext = StringToBlocks(sDemo);

        byte[] key = new byte[16];

        byte bI;

        for (bI = 0; bI < key.Length; bI++)
        {
            key[bI] = bI;
        }

        byte[] iv = new byte[Blowfish.BLOCKSIZE];
        for (bI = 0; bI < iv.Length; bI++)
        {
            iv[bI] = (byte)bI;
        }

        BlowfishCBC bfc = new BlowfishCBC(key, iv);

        byte[] ctext = new byte[ptext.Length];

        bfc.Encrypt(ptext, ctext, 0, 0, ptext.Length);

        System.Console.WriteLine(BlocksToString(ctext));

        bfc.Iv = iv;

        bfc.Decrypt(ctext, ctext, 0, 0, ctext.Length);

        bfc.Burn();

        System.Console.WriteLine(BlocksToString(ctext));
    }