示例#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 string encryptString(string decrypted, string password)
        {
            byte[] iv        = getbytes("12345678");
            int    blocksize = iv.Length;
            int    numblocks = (decrypted.Length / blocksize) + 1;
            int    decSize   = decrypted.Length;

            //pad the string with nulls so that it is a multiple of blocksize
            for (int i = decSize; i < numblocks * blocksize; i++)
            {
                decrypted += '\0';
            }

            byte[] plain     = getbytes(decrypted);
            byte[] encrypted = new byte[plain.Length];
            Array.Clear(encrypted, 0, encrypted.Length);
            byte[]      key = getbytes(password);
            BlowfishCBC bfc = new BlowfishCBC();

            bfc.IV = iv;
            bfc.Initialize(key, 0, key.Length);
            bfc.Encrypt(plain, 0, encrypted, 0, plain.Length);
            return(string2hex(getstring(encrypted)));
        }