Пример #1
0
		/// <exception cref="System.Exception"></exception>
		public override void Init(int mode, byte[] key, byte[] iv)
		{
			string pad = "NoPadding";
			byte[] tmp;
			if (iv.Length > ivsize)
			{
				tmp = new byte[ivsize];
				System.Array.Copy(iv, 0, tmp, 0, tmp.Length);
				iv = tmp;
			}
			if (key.Length > bsize)
			{
				tmp = new byte[bsize];
				System.Array.Copy(key, 0, tmp, 0, tmp.Length);
				key = tmp;
			}
			try
			{
				SecretKeySpec keyspec = new SecretKeySpec(key, "AES");
				cipher = Sharpen.Cipher.GetInstance("AES/CBC/" + pad);
				cipher.Init((mode == ENCRYPT_MODE ? Sharpen.Cipher.ENCRYPT_MODE : Sharpen.Cipher.
					DECRYPT_MODE), keyspec, new IvParameterSpec(iv));
			}
			catch (Exception e)
			{
				cipher = null;
				throw;
			}
		}
 /// <exception cref="System.Exception"></exception>
 public override void Init(int mode, byte[] key, byte[] iv)
 {
     byte[] tmp;
     if (key.Length > bsize)
     {
         tmp = new byte[bsize];
         System.Array.Copy(key, 0, tmp, 0, tmp.Length);
         key = tmp;
     }
     try
     {
         cipher = Sharpen.Cipher.GetInstance("RC4");
         SecretKeySpec _key = new SecretKeySpec(key, "RC4");
         cipher.Init((mode == ENCRYPT_MODE ? Sharpen.Cipher.ENCRYPT_MODE : Sharpen.Cipher.
                      DECRYPT_MODE), _key);
         byte[] foo = new byte[1];
         for (int i = 0; i < skip; i++)
         {
             cipher.Update(foo, 0, 1, foo, 0);
         }
     }
     catch (Exception e)
     {
         cipher = null;
         throw;
     }
 }
Пример #3
0
		/// <exception cref="System.Exception"></exception>
		public override void Init(int mode, byte[] key, byte[] iv)
		{
			byte[] tmp;
			if (key.Length > bsize)
			{
				tmp = new byte[bsize];
				System.Array.Copy(key, 0, tmp, 0, tmp.Length);
				key = tmp;
			}
			try
			{
				cipher = Sharpen.Cipher.GetInstance("RC4");
				SecretKeySpec _key = new SecretKeySpec(key, "RC4");
				cipher.Init((mode == ENCRYPT_MODE ? Sharpen.Cipher.ENCRYPT_MODE : Sharpen.Cipher.
					DECRYPT_MODE), _key);
				byte[] foo = new byte[1];
				for (int i = 0; i < skip; i++)
				{
					cipher.Update(foo, 0, 1, foo, 0);
				}
			}
			catch (Exception e)
			{
				cipher = null;
				throw;
			}
		}
Пример #4
0
		/// <exception cref="System.Exception"></exception>
		public override void Init(int mode, byte[] key, byte[] iv)
		{
			string pad = "NoPadding";
			//if(padding) pad="PKCS5Padding";
			byte[] tmp;
			if (iv.Length > ivsize)
			{
				tmp = new byte[ivsize];
				System.Array.Copy(iv, 0, tmp, 0, tmp.Length);
				iv = tmp;
			}
			if (key.Length > bsize)
			{
				tmp = new byte[bsize];
				System.Array.Copy(key, 0, tmp, 0, tmp.Length);
				key = tmp;
			}
			try
			{
				cipher = Sharpen.Cipher.GetInstance("DESede/CTR/" + pad);
				DESedeKeySpec keyspec = new DESedeKeySpec(key);
				SecretKeyFactory keyfactory = SecretKeyFactory.GetInstance("DESede");
				SecretKey _key = keyfactory.GenerateSecret(keyspec);
				cipher.Init((mode == ENCRYPT_MODE ? Sharpen.Cipher.ENCRYPT_MODE : Sharpen.Cipher.
					DECRYPT_MODE), _key, new IvParameterSpec(iv));
			}
			catch (Exception e)
			{
				cipher = null;
				throw;
			}
		}
        /// <exception cref="System.Exception"></exception>
        public override void Init(int mode, byte[] key, byte[] iv)
        {
            string pad = "NoPadding";

            //  if(padding) pad="PKCS5Padding";
            byte[] tmp;
            if (iv.Length > ivsize)
            {
                tmp = new byte[ivsize];
                System.Array.Copy(iv, 0, tmp, 0, tmp.Length);
                iv = tmp;
            }
            if (key.Length > bsize)
            {
                tmp = new byte[bsize];
                System.Array.Copy(key, 0, tmp, 0, tmp.Length);
                key = tmp;
            }
            try
            {
                SecretKeySpec skeySpec = new SecretKeySpec(key, "Blowfish");
                cipher = Sharpen.Cipher.GetInstance("Blowfish/CBC/" + pad);
                cipher.Init((mode == ENCRYPT_MODE ? Sharpen.Cipher.ENCRYPT_MODE : Sharpen.Cipher.
                             DECRYPT_MODE), skeySpec, new IvParameterSpec(iv));
            }
            catch (Exception e)
            {
                throw;
            }
        }
Пример #6
0
        /// <exception cref="System.Exception"></exception>
        public override void Init(int mode, byte[] key, byte[] iv)
        {
            string pad = "NoPadding";

            //if(padding) pad="PKCS5Padding";
            byte[] tmp;
            if (iv.Length > ivsize)
            {
                tmp = new byte[ivsize];
                System.Array.Copy(iv, 0, tmp, 0, tmp.Length);
                iv = tmp;
            }
            if (key.Length > bsize)
            {
                tmp = new byte[bsize];
                System.Array.Copy(key, 0, tmp, 0, tmp.Length);
                key = tmp;
            }
            try
            {
                cipher = Sharpen.Cipher.GetInstance("DESede/CTR/" + pad);
                DESedeKeySpec    keyspec    = new DESedeKeySpec(key);
                SecretKeyFactory keyfactory = SecretKeyFactory.GetInstance("DESede");
                SecretKey        _key       = keyfactory.GenerateSecret(keyspec);
                cipher.Init((mode == ENCRYPT_MODE ? Sharpen.Cipher.ENCRYPT_MODE : Sharpen.Cipher.
                             DECRYPT_MODE), _key, new IvParameterSpec(iv));
            }
            catch (Exception e)
            {
                cipher = null;
                throw;
            }
        }
Пример #7
0
 /// <exception cref="System.IO.IOException"></exception>
 internal override InputStream Decrypt(InputStream @in)
 {
     try
     {
         Sharpen.Cipher c = Sharpen.Cipher.GetInstance(algorithmName);
         c.Init(Sharpen.Cipher.DECRYPT_MODE, skey, aspec);
         return(new CipherInputStream(@in, c));
     }
     catch (NoSuchAlgorithmException e)
     {
         throw Error(e);
     }
     catch (NoSuchPaddingException e)
     {
         throw Error(e);
     }
     catch (InvalidKeyException e)
     {
         throw Error(e);
     }
     catch (InvalidAlgorithmParameterException e)
     {
         throw Error(e);
     }
 }
Пример #8
0
 /// <exception cref="System.IO.IOException"></exception>
 internal override OutputStream Encrypt(OutputStream os)
 {
     try
     {
         Sharpen.Cipher c = Sharpen.Cipher.GetInstance(algorithmName);
         c.Init(Sharpen.Cipher.ENCRYPT_MODE, skey, aspec);
         return(new CipherOutputStream(os, c));
     }
     catch (NoSuchAlgorithmException e)
     {
         throw Error(e);
     }
     catch (NoSuchPaddingException e)
     {
         throw Error(e);
     }
     catch (InvalidKeyException e)
     {
         throw Error(e);
     }
     catch (InvalidAlgorithmParameterException e)
     {
         throw Error(e);
     }
 }
Пример #9
0
		/// <exception cref="System.Exception"></exception>
		public override void Init(int mode, byte[] key, byte[] iv)
		{
			string pad = "NoPadding";
			byte[] tmp;
			if (key.Length > bsize)
			{
				tmp = new byte[bsize];
				System.Array.Copy(key, 0, tmp, 0, tmp.Length);
				key = tmp;
			}
			try
			{
				cipher = Sharpen.Cipher.GetInstance("RC4");
				SecretKeySpec _key = new SecretKeySpec(key, "RC4");
				cipher.Init((mode == ENCRYPT_MODE ? Sharpen.Cipher.ENCRYPT_MODE : Sharpen.Cipher.
					DECRYPT_MODE), _key);
			}
			catch (Exception e)
			{
				cipher = null;
				throw;
			}
		}
        /// <exception cref="System.Exception"></exception>
        public override void Init(int mode, byte[] key, byte[] iv)
        {
            string pad = "NoPadding";

            byte[] tmp;
            if (key.Length > bsize)
            {
                tmp = new byte[bsize];
                System.Array.Copy(key, 0, tmp, 0, tmp.Length);
                key = tmp;
            }
            try
            {
                cipher = Sharpen.Cipher.GetInstance("RC4");
                SecretKeySpec _key = new SecretKeySpec(key, "RC4");
                cipher.Init((mode == ENCRYPT_MODE ? Sharpen.Cipher.ENCRYPT_MODE : Sharpen.Cipher.
                             DECRYPT_MODE), _key);
            }
            catch (Exception e)
            {
                cipher = null;
                throw;
            }
        }