Esempio n. 1
0
 /// <summary>
 /// Decrypts a byte array with the specified decrypt mode
 /// </summary>
 /// <param name="cipherText">The bytes to be decrypted</param>
 /// <param name="decryptMode">The mode to decrypt with</param>
 /// <returns>The decrypted bytes</returns>
 public byte[] Decrypt(byte[] cipherText, BlowFishMode decryptMode)
 {
     switch (decryptMode)
     {
         case BlowFishMode.CBC:
             return Crypt_CBC(cipherText, true);
         case BlowFishMode.CTR:
             return Crypt_CTR(cipherText, 2);
         case BlowFishMode.ECB:
             return Crypt_ECB(cipherText, true);
     }
     return null;
 }
Esempio n. 2
0
 /// <summary>
 /// Encrypts a string with the specified encrypt mode
 /// </summary>
 /// <param name="cipherTextString">The string be decrypted</param>
 /// <param name="encryptMode">The mode to encrypt with</param>
 /// <returns>The encrypted string</returns>
 public string Encrypt(string cipherTextString, BlowFishMode encryptMode)
 {
     if (!_ivSet && encryptMode != BlowFishMode.ECB)
         SetRandomIV();
     var cipherText = Encoding.ASCII.GetBytes(cipherTextString);
     switch (encryptMode)
     {
         case BlowFishMode.CTR:
             return ByteToHex(_initVector) + ByteToHex(Crypt_CTR(cipherText, 2));
         case BlowFishMode.ECB:
             return ByteToHex(Crypt_ECB(cipherText, false));
         case BlowFishMode.CBC:
             return ByteToHex(_initVector) + ByteToHex(Crypt_CBC(cipherText, false));
     }
     return null;
 }
Esempio n. 3
0
        /// <summary>
        /// Encrypts a byte array with the specified encrypt mode
        /// </summary>
        /// <param name="cipherText">The bytes be decrypted</param>
        /// <param name="encryptMode">The mode to encrypt with</param>
        /// <returns>The encrypted bytes</returns>
        public byte[] Encrypt(byte[] cipherText, BlowFishMode encryptMode)
        {
            if (!_ivSet && encryptMode != BlowFishMode.ECB)
                SetRandomIV();

            switch (encryptMode)
            {
                case BlowFishMode.CTR:
                    return Crypt_CTR(cipherText, 2);
                case BlowFishMode.ECB:
                    return Crypt_ECB(cipherText, false);
                case BlowFishMode.CBC:
                    return Crypt_CBC(cipherText, false);
            }
            return null;
        }
Esempio n. 4
0
        /// <summary>
        /// Decrypts a string with the specified decrypt mode
        /// </summary>
        /// <param name="cipherTextString">The string be decrypted</param>
        /// <param name="decryptMode">The mode to decrypt with</param>
        /// <returns>The decrypted string</returns>
        public string Decrypt(string cipherTextString, BlowFishMode decryptMode)
        {
            if (decryptMode != BlowFishMode.ECB)
                IV = HexToByte(cipherTextString.Substring(0, 16));


            var cipherText = HexToByte(cipherTextString);

            if (decryptMode == BlowFishMode.CTR)
                cipherText = HexToByte(cipherTextString.Substring(16));

            switch (decryptMode)
            {
                case BlowFishMode.CBC:
                    return Encoding.ASCII.GetString(Crypt_CBC(cipherText, true)).Replace(@"", "");
                case BlowFishMode.CTR:
                    return Encoding.ASCII.GetString(Crypt_CTR(cipherText, 2)).Replace(@"", "");
                case BlowFishMode.ECB:
                    return Encoding.ASCII.GetString(Crypt_ECB(cipherText, true)).Replace(@"", "");
            }
            return null;
        }
Esempio n. 5
0
 /// <summary>
 /// Encrypts a string with the specified encrypt mode
 /// </summary>
 /// <param name="cipherTextString">The string be decrypted</param>
 /// <param name="encryptMode">The mode to encrypt with</param>
 /// <returns>The encrypted string</returns>
 public string Encrypt(string cipherTextString, BlowFishMode encryptMode)
 {
     if (!_ivSet && encryptMode != BlowFishMode.ECB)
         SetRandomIV();
     var cipherText = Encoding.ASCII.GetBytes(cipherTextString);
     switch (encryptMode)
     {
         case BlowFishMode.CTR:
             return ByteToHex(_initVector) + ByteToHex(Crypt_CTR(cipherText, 2));
         case BlowFishMode.ECB:
             return ByteToHex(Crypt_ECB(cipherText, false));
         case BlowFishMode.CBC:
             return ByteToHex(_initVector) + ByteToHex(Crypt_CBC(cipherText, false));
     }
     return null;
 }
Esempio n. 6
0
        /// <summary>
        /// Encrypts a byte array with the specified encrypt mode
        /// </summary>
        /// <param name="cipherText">The bytes be decrypted</param>
        /// <param name="encryptMode">The mode to encrypt with</param>
        /// <returns>The encrypted bytes</returns>
        public byte[] Encrypt(byte[] cipherText, BlowFishMode encryptMode)
        {
            if (!_ivSet && encryptMode != BlowFishMode.ECB)
                SetRandomIV();

            switch (encryptMode)
            {
                case BlowFishMode.CTR:
                    return Crypt_CTR(cipherText, 2);
                case BlowFishMode.ECB:
                    return Crypt_ECB(cipherText, false);
                case BlowFishMode.CBC:
                    return Crypt_CBC(cipherText, false);
            }
            return null;
        }
Esempio n. 7
0
        /// <summary>
        /// Decrypts a string with the specified decrypt mode
        /// </summary>
        /// <param name="cipherTextString">The string be decrypted</param>
        /// <param name="decryptMode">The mode to decrypt with</param>
        /// <returns>The decrypted string</returns>
        public string Decrypt(string cipherTextString, BlowFishMode decryptMode)
        {
            if (decryptMode != BlowFishMode.ECB)
                IV = HexToByte(cipherTextString.Substring(0, 16));

            var cipherText = HexToByte(cipherTextString);

            if (decryptMode == BlowFishMode.CTR)
                cipherText = HexToByte(cipherTextString.Substring(16));

            switch (decryptMode)
            {
                case BlowFishMode.CBC:
                    return Encoding.ASCII.GetString(Crypt_CBC(cipherText, true)).Replace(@"", "");
                case BlowFishMode.CTR:
                    return Encoding.ASCII.GetString(Crypt_CTR(cipherText, 2)).Replace(@"", "");
                case BlowFishMode.ECB:
                    return Encoding.ASCII.GetString(Crypt_ECB(cipherText, true)).Replace(@"", "");
            }
            return null;
        }
Esempio n. 8
0
 /// <summary>
 /// Decrypts a byte array with the specified decrypt mode
 /// </summary>
 /// <param name="cipherText">The bytes to be decrypted</param>
 /// <param name="decryptMode">The mode to decrypt with</param>
 /// <returns>The decrypted bytes</returns>
 public byte[] Decrypt(byte[] cipherText, BlowFishMode decryptMode)
 {
     switch (decryptMode)
     {
         case BlowFishMode.CBC:
             return Crypt_CBC(cipherText, true);
         case BlowFishMode.CTR:
             return Crypt_CTR(cipherText, 2);
         case BlowFishMode.ECB:
             return Crypt_ECB(cipherText, true);
     }
     return null;
 }