Exemplo n.º 1
0
        public void TestEncrypt()
        {
            byte[] abKey = SimpleAES.SimpleAES.GenerateEncryptionKey();
            byte[] abIV  = SimpleAES.SimpleAES.GenerateEncryptionVector();;

            string sMessageIn = "I'm a lumberjack and I'm OK, I sleep all night and I work all day.";

            SimpleAES.SimpleAES crypt = new SimpleAES.SimpleAES(abKey, abIV);
            byte[] abEncrypted        = crypt.Encrypt(sMessageIn);
            string sMessageOut        = crypt.Decrypt(abEncrypted);

            Console.WriteLine(sMessageOut);

            Assert.That(sMessageOut, Is.EqualTo(sMessageIn));
        }
Exemplo n.º 2
0
            }             // LoadFromTable

            public bool LoadUsingSql(string i_sSqlCommandText)
            {
                bool bRet = true;

                using (IDbConnection sqlConn = GetDbConnection())
                    using (IDbCommand sqlCmd = sqlConn.CreateCommand())
                    {
                        sqlCmd.CommandText = i_sSqlCommandText;
                        sqlConn.Open();

                        using (IDataReader sqlReader = sqlCmd.ExecuteReader())
                        {
                            if (sqlReader.Read())                       // Only gets first match
                            {
                                PopulateFromReader(sqlReader);

#if (USE_INLINEDECRYPT)
                                long lRes = 0;
                                // This may not be safe, since the member is public
                                lRes          = sqlReader.GetBytes(12, 0, null, 0, 0);
                                this.Passcode = new byte[lRes];
                                lRes          = sqlReader.GetBytes(12, 0, this.Passcode, 0, (int)lRes);

                                lRes          = sqlReader.GetBytes(13, 0, null, 0, 0);
                                this.Password = new byte[lRes];
                                lRes          = sqlReader.GetBytes(13, 0, this.Password, 0, (int)lRes);

                                lRes    = sqlReader.GetBytes(14, 0, null, 0, 0);
                                this.IV = new byte[lRes];
                                lRes    = sqlReader.GetBytes(14, 0, this.IV, 0, (int)lRes);

                                byte[] abKey             = SimpleAES.SimpleAES.RetrieveKey();
                                SimpleAES.SimpleAES saes = new SimpleAES.SimpleAES(abKey, this.IV);
                                m_sPassword = saes.Decrypt(this.Password);

                                Console.Error.WriteLine(DateTime.Now.ToString() + " ###Pwd in LoadFromTable(userid): '" + m_sPassword + "'");
                                Console.Error.WriteLine(DateTime.Now.ToString() + " ###Data in LoadFromTable: abPassword = "******", abIV = " + SBConfigStor.Directory.ByteArrayToPgsqlOctalString(this.IV));
#else
                                bool      bRes = true;
                                byte[]    abPcd = null, abPwd = null, abIV = null;
                                string    sPcd = "", sPwd = "";
                                Directory dir = new Directory();
                                bRes = dir.GetPassByUserid(this.UserID, out abPcd, out abPwd, out abIV, out sPcd, out sPwd);

                                this.Passcode = abPcd;
                                this.Password = abPwd;
                                this.IV       = abIV;
                                m_sPassword   = sPwd;
#endif
                            }
                            else
                            {
                                bRet = false;
                            }
                        }

                        sqlConn.Close();
                    }

                return(bRet);
            }             // LoadUsingSql