Ejemplo n.º 1
0
        public static void performPoly1305MAC(string text)
        {
            Chilkat.Crypt2 crypt = new Chilkat.Crypt2();

            bool success = crypt.UnlockComponent("Anything for 30-day trial");

            if (success != true)
            {
                Console.WriteLine(crypt.LastErrorText);
                return;
            }

            //  Set the MAC algorithm to poly1305
            crypt.MacAlgorithm = "poly1305";

            //  EncodingMode specifies the encoding of the output for
            //  encryption, and the input for decryption.
            //  Valid modes are (case insensitive) "Base64", "modBase64", "Base32", "Base58", "UU",
            //  "QP" (for quoted-printable), "URL" (for url-encoding), "Hex",
            //  "Q", "B", "url_oauth", "url_rfc1738", "url_rfc2396", and "url_rfc3986".
            crypt.EncodingMode = "hex";

            //  Poly1305 always uses a 32-byte (256-bit) MAC key.
            string keyHex = "1c9240a5eb55d38af333888604f6b5f0473917c1402b80099dca5cbc207075c0";

            success = crypt.SetMacKeyEncoded(keyHex, "hex");

            string plainText = "'Twas brillig, and the slithy toves\nDid gyre and gimble in the wabe:\nAll mimsy were the borogoves,\nAnd the mome raths outgrabe.";

            //  The computed tag should match the Tag shown below.
            //  (Note: hexidecimal encoding is case insensitive.)
            string encTag = crypt.MacStringENC(text);
            //Console.WriteLine(encTag);
        }