コード例 #1
0
        public byte[] EncryptText(EncryptTextMessage message)
        {
            byte[] encryptedText = null;
            //Odradi se enkripcija
            if (message.Algorithm == AlgorithmType.RC4)
            {
                RC4 rc = new RC4(message.Key, message.IV);
                encryptedText = rc.Crypt(message.Data);
            }
            else if (message.Algorithm == AlgorithmType.RC4CTR)
            {
                RC4 rc = new RC4(message.Key, message.IV);
                encryptedText = rc.CryptWithCTR(message.Data);
            }
            else if (message.Algorithm == AlgorithmType.A52 || message.Algorithm == AlgorithmType.A52CTR)
            {
                A52 alg = new A52();
                alg.SetKey(message.Key);
                alg.SetF(message.FKeyA52);

                if (message.Algorithm == AlgorithmType.A52)
                {
                    encryptedText = alg.Crypt(message.Data);
                }
                else
                {
                    alg.SetIV(message.IV);
                    encryptedText = alg.CryptWithCTR(message.Data);
                }
            }
            else if (message.Algorithm == AlgorithmType.RSA)
            {
                RSA rsa = new RSA();
                rsa.E = new BigInteger(message.Key);
                rsa.P = new BigInteger(message.P);
                rsa.Q = new BigInteger(message.Q);
                rsa.GenerateRSA();
                //BigInteger result = rsa.Crypt(new BigInteger(message.Data));
                //encryptedText = result.ToByteArray();
                encryptedText = rsa.Crypt(message.Data);
            }
            else if (message.Algorithm == AlgorithmType.TigerHash)
            {
                TigerHash th  = new TigerHash();
                byte[]    msg = message.Data;
                encryptedText = th.ComputeHash(message.Data);
            }
            return(encryptedText);
        }
コード例 #2
0
        public byte[] DecryptText(EncryptTextMessage message)
        {
            byte[] decryptedText = null;
            //Odradi se enkripcija
            if (message.Algorithm == AlgorithmType.RC4)
            {
                RC4 rc = new RC4(message.Key, message.IV);
                decryptedText = rc.Decrypt(message.Data);
            }
            else if (message.Algorithm == AlgorithmType.RC4CTR)
            {
                RC4 rc = new RC4(message.Key, message.IV);
                decryptedText = rc.DecryptWithCTR(message.Data);
            }
            else if (message.Algorithm == AlgorithmType.A52 || message.Algorithm == AlgorithmType.A52CTR)
            {
                A52 alg = new A52();
                alg.SetKey(message.Key);
                alg.SetF(message.FKeyA52);

                if (message.Algorithm == AlgorithmType.A52)
                {
                    decryptedText = alg.Decrypt(message.Data);
                }
                else
                {
                    alg.SetIV(message.IV);
                    decryptedText = alg.DecryptWithCTR(message.Data);
                }
            }
            else if (message.Algorithm == AlgorithmType.RSA)
            {
                RSA rsa = new RSA();
                rsa.E = new BigInteger(message.Key);
                rsa.P = new BigInteger(message.P);
                rsa.Q = new BigInteger(message.Q);
                rsa.GenerateRSA();
                //BigInteger result = rsa.Decrypt(new BigInteger(message.Data));
                //decryptedText = result.ToByteArray();
                decryptedText = rsa.Decrypt(message.Data);
            }

            return(decryptedText);
        }