Exemplo n.º 1
0
        static void Main(string[] args)
        {
            string plaintext = null;
            int    _enterResult;


            Console.WriteLine("To get password from database enter 1 , to insert new password or update enter 2");
            _enterResult = Convert.ToInt32(Console.ReadLine());
            if (_enterResult == 2)
            {
                Console.WriteLine("Enter new password:\n");
                plaintext = Console.ReadLine();
            }
            switch (_enterResult)
            {
            case 1:
                DatabaseParam databaseParam1 = new DatabaseParam();
                databaseParam1 = DatabaseLayer.ReturnPassword();
                EncryptionDetails encryptionDetails1 = new EncryptionDetails();
                encryptionDetails1.ciphertext = ConvertToByteArray(databaseParam1._strCiphertext);
                encryptionDetails1.iv         = ConvertToByteArray(databaseParam1._strIV);
                encryptionDetails1.key        = ConvertToByteArray(databaseParam1._strKey);
                plaintext = null;
                plaintext = RijndaelEncryption.DecryptStringFromBytes(encryptionDetails1);
                Console.WriteLine("So the password saved in Database is : \n {0}", plaintext);
                Console.ReadLine();
                break;

            case 2:
                EncryptionDetails encryptionDetails2 = new EncryptionDetails();
                encryptionDetails2 = RijndaelEncryption.EncryptStringToBytes(plaintext);
                DatabaseParam databaseParam2 = new DatabaseParam(CreateString(encryptionDetails2.ciphertext),
                                                                 CreateString(encryptionDetails2.iv),
                                                                 CreateString(encryptionDetails2.key));
                DatabaseLayer.InsertUpdatePassword(databaseParam2);
                break;

            default:
                Console.WriteLine("Please enter corect number");
                break;
            }
        }