コード例 #1
0
        public static byte[] Encrypt(byte[] plainbytes, bool compress)
        {
            byte[] buffer;
            byte   compressFlag;

            if (plainbytes.Length > MINIMUM_LENGTH_FOR_COMPRESSION)
            {
                compressFlag = Convert.ToByte(COMPRESSED);
                buffer       = CompressionHelper.Deflate(plainbytes);
            }
            else
            {
                compressFlag = Convert.ToByte(NOTCOMPRESSED);
                buffer       = plainbytes;
            }

            byte[] encryptedBytes = Obviex.CipherLite.Rijndael.Encrypt(CompressionHelper.BytesToString(buffer),
                                                                       "this is a pass phrase", null, KEY_SIZE, PASSWORD_ITERATIONS, "this is a salt value", HASH_ALGORITHM);

            //SettingHelper.GetSetting("Security.Cipher.PassPhrase"), SettingHelper.GetSetting("Security.Cipher.InitVector"), KEY_SIZE, PASSWORD_ITERATIONS, SettingHelper.GetSetting("Security.Cipher.Salt"), HASH_ALGORITHM);
            byte[] toReturn = new byte[encryptedBytes.Length + 1];

            int index = 0;

            toReturn[index++] = compressFlag;
            for (int i = 0; i < encryptedBytes.Length; i++)
            {
                toReturn[index++] = encryptedBytes[i];
            }

            return(toReturn);
        }
コード例 #2
0
 public static string Encrypt(string plaintext, bool compress)
 {
     return(CompressionHelper.BytesToString(Encrypt(CompressionHelper.StringToBytes(plaintext), compress)));
 }