Esempio n. 1
0
    public static byte[] encode(byte[] inputByteArray)
    {
        byte[]       rgbKey = Encoding.UTF8.GetBytes(ekey);
        byte[]       rgbIV  = Encoding.UTF8.GetBytes(eiv);
        PKCS5Padding pp     = new PKCS5Padding();

        byte[]    pss = pp.Pad(8, inputByteArray);
        DesCipher cc  = new DesCipher(rgbKey, new CbcCipherMode(rgbIV), null);

        return(cc.Encrypt(pss));
    }
        public void Cbc_Encrypt()
        {
            var expectedCypher = new byte[]
            {
                0x15, 0x43, 0x3e, 0x97, 0x65, 0x66, 0xea, 0x81, 0x22, 0xab, 0xe3,
                0x11, 0x0f, 0x7d, 0xcb, 0x78, 0x56, 0x91, 0x22, 0x3d, 0xd6, 0xca,
                0xe3, 0xbd
            };

            var input = Encoding.ASCII.GetBytes("www.javaCODEgeeks.com!!!");
            var key   = new byte[] { 0x01, 0x23, 0x45, 0x67, 0x89, 0xab, 0xcd, 0xef };
            var iv    = new byte[] { 0x07, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01, 0x00 };

            var des          = new DesCipher(key, new CbcCipherMode(iv), new PKCS7Padding());
            var actualCypher = des.Encrypt(input);

            Assert.IsTrue((expectedCypher.IsEqualTo(actualCypher)));
        }