Example #1
0
        public void CipherTest()
        {
            Random rnd = new Random();

            byte[] message = new byte[511];
            rnd.NextBytes(message);
            BFCText encypted = BFCipher.encrypt(pKey, message, rnd);

            byte[] result = BFCipher.decrypt(encypted, key);
            Assert.AreEqual(Encoding.UTF8.GetString(message, 0, message.Length), Encoding.UTF8.GetString(result, 0, message.Length));
        }
Example #2
0
        public async Task <string> CipherMessage(byte[] message, string identity, SerializedPrivateKey sKey)
        {
            var cipherTask = Task <BFCText> .Factory.StartNew(() =>
            {
                BFUserPrivateKey key = new BFUserPrivateKey(sKey);
                BFUserPublicKey pKey = new BFUserPublicKey(identity, key.Param);
                return(BFCipher.encrypt(pKey, message, new Random()));
            });

            await   cipherTask;
            BFCText cipher = (BFCText)cipherTask.Result;

            return(HttpUtility.UrlEncode(JsonConvert.SerializeObject(cipher.Serialize())));
        }
Example #3
0
        public void CipherTest()
        {
            KeyPair victor = BFCipher.Extract(master, "victor", new Random());
            String  msg    = "hola";

            byte[]  msgByte;
            byte[]  plainByte;
            String  plain;
            BFCText encrypted;

            msgByte   = Encoding.UTF8.GetBytes(msg);
            encrypted = BFCipher.encrypt((BFUserPublicKey)victor.Public, msgByte, new Random());
            plainByte = BFCipher.decrypt(encrypted, (BFUserPrivateKey)victor.Private);
            plain     = Encoding.UTF8.GetString(plainByte);
            Assert.AreEqual(msg, plain);
        }
Example #4
0
        public void CipherInReasonableTimeTest()
        {
            int times = 50;
            int size  = 511;

            long[] measures = new long[50];
            Random rnd      = new Random();

            System.Diagnostics.Stopwatch m_watch = new System.Diagnostics.Stopwatch();
            m_watch.Start();
            for (int i = 0; i < times; i++)
            {
                byte[] message = new byte[size];
                rnd.NextBytes(message);
                m_watch.Reset();
                m_watch.Start();
                BFCipher.encrypt(pKey, message, rnd);
                measures[i] = m_watch.ElapsedMilliseconds;
                m_watch.Stop();
            }
            string prompt = "Time spent to cipher " + times + " messages of " + size + " bytes:";

            System.Diagnostics.Debug.WriteLine("{0}  {1} msec", prompt, m_watch.ElapsedMilliseconds);
        }