Beispiel #1
0
        public void Configure(Crypt2 crypt)
        {
            crypt.UnlockComponent("Anything for 30-day trial.");



            //  Set the encryption algorithm to chacha20
            //  chacha20 is a stream cipher, and therefore no cipher mode applies.
            crypt.CryptAlgorithm = "chacha20";

            //  The key length for chacha20 is always 256-bits.
            crypt.KeyLength = 256;

            //  Note: "padding" only applies to block encryption algorithmns.
            //  Since chacha20 is a stream cipher, there is no padding and the output
            //  number of bytes is exactly equal to the input.

            //  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";

            //  The inputs to ChaCha20 encryption, specified by RFC 7539, are:
            //  1) A 256-bit secret key.
            //  2) A 96-bit nonce.
            //  3) A 32-bit initial count.
            //  The IV property is used to specify the chacha20 nonce.
            //  For a 96-bit nonce, the IV should be 12 bytes in length.
            //
            //  Note: Some implementations of chacha20, such as that used internally by SSH,
            //  use a 64-bit nonce and 64-bit count.  To do chacha20 encryption in this way,
            //  simply provide 8 bytes for the IV instead of 12 bytes.  Chilkat will then automatically
            //  use 8 bytes (64-bits) for the count.

            //  This example duplicates Test Vector #3 (for ChaCha20 encryption) from RFC 7539.
            const string ivHex = "000000000000000000000002";

            crypt.SetEncodedIV(ivHex, "hex");

            crypt.InitialCount = 42;

            var keyHex = Keys.ChaCha20_KeyString;

            crypt.SetEncodedKey(keyHex, "hex");
        }
Beispiel #2
0
        public void Configure(Crypt2 crypt)
        {
            crypt.UnlockComponent("Anything for 30-day trial.");


            //  Set the encryption algorithm = "rc2"
            crypt.CryptAlgorithm = "rc2";

            //  CipherMode may be "ecb" or "cbc"
            crypt.CipherMode = "ecb";

            //  KeyLength may range from 8 bits to 1024 bits
            crypt.KeyLength = 128;

            //  RC2 also has an effective key length property
            //  which can also range from 8 bits to 1024 bits:
            crypt.Rc2EffectiveKeyLength = 128;

            //  The padding scheme determines the contents of the bytes
            //  that are added to pad the result to a multiple of the
            //  encryption algorithm's block size.  RC2 has a block
            //  size of 8 bytes, so encrypted output is always
            //  a multiple of 8.
            crypt.PaddingScheme = 0;

            //  EncodingMode specifies the encoding of the output for
            //  encryption, and the input for decryption.
            //  It may be "hex", "url", "base64", or "quoted-printable".
            crypt.EncodingMode = "hex";

            //  An initialization vector is required if using CBC mode.
            //  ECB mode does not use an IV.
            //  The length of the IV is equal to the algorithm's block size.
            //  It is NOT equal to the length of the key.
            const string ivHex = "0001020304050607";

            crypt.SetEncodedIV(ivHex, "hex");

            //  The secret key must equal the size of the key.
            //  For 128-bit encryption, the binary secret key is 16 bytes.
            var keyHex = Keys.RC2_ECB_KeyString;

            crypt.SetEncodedKey(keyHex, "hex");
        }
Beispiel #3
0
        public void Configure(Crypt2 crypt)
        {
            crypt.UnlockComponent("Anything for 30-day trial.");


            //  AES is also known as Rijndael.
            crypt.CryptAlgorithm = "aes";

            //  CipherMode may be "ecb", "cbc", "ofb", "cfb", "gcm", etc.
            //  Note: Check the online reference documentation to see the Chilkat versions
            //  when certain cipher modes were introduced.
            crypt.CipherMode = "cbc";

            //  KeyLength may be 128, 192, 256
            crypt.KeyLength = 256;

            //  The padding scheme determines the contents of the bytes
            //  that are added to pad the result to a multiple of the
            //  encryption algorithm's block size.  AES has a block
            //  size of 16 bytes, so encrypted output is always
            //  a multiple of 16.
            crypt.PaddingScheme = 0;

            //  EncodingMode specifies the encoding of the output for
            //  encryption, and the input for decryption.
            //  It may be "hex", "url", "base64", or "quoted-printable".
            crypt.EncodingMode = "hex";

            //  An initialization vector is required if using CBC mode.
            //  ECB mode does not use an IV.
            //  The length of the IV is equal to the algorithm's block size.
            //  It is NOT equal to the length of the key.
            const string ivHex = "000102030405060708090A0B0C0D0E0F";

            crypt.SetEncodedIV(ivHex, "hex");

            //  The secret key must equal the size of the key.  For
            //  256-bit encryption, the binary secret key is 32 bytes.
            //  For 128-bit encryption, the binary secret key is 16 bytes.
            var keyHex = Keys.AES_KeyString;

            crypt.SetEncodedKey(keyHex, "hex");
        }
Beispiel #4
0
        public void Configure(Crypt2 crypt)
        {
            crypt.UnlockComponent("Anything for 30-day trial.");


            //  Specify 3DES for the encryption algorithm:
            crypt.CryptAlgorithm = "3des";

            //  CipherMode may be "ecb" or "cbc"
            crypt.CipherMode = "cbc";

            //  KeyLength must be 192.  3DES is technically 168-bits;
            //  the most-significant bit of each key byte is a parity bit,
            //  so we must indicate a KeyLength of 192, which includes
            //  the parity bits.
            crypt.KeyLength = 192;

            //  The padding scheme determines the contents of the bytes
            //  that are added to pad the result to a multiple of the
            //  encryption algorithm's block size.  3DES has a block
            //  size of 8 bytes, so encrypted output is always
            //  a multiple of 8.
            crypt.PaddingScheme = 0;

            //  EncodingMode specifies the encoding of the output for
            //  encryption, and the input for decryption.
            //  It may be "hex", "url", "base64", or "quoted-printable".
            crypt.EncodingMode = "hex";

            //  An initialization vector is required if using CBC or CFB modes.
            //  ECB mode does not use an IV.
            //  The length of the IV is equal to the algorithm's block size.
            //  It is NOT equal to the length of the key.
            const string ivHex = "0001020304050607";

            crypt.SetEncodedIV(ivHex, "hex");

            //  The secret key must equal the size of the key.  For
            //  3DES, the key must be 24 bytes (i.e. 192-bits).
            var keyHex = Keys.ThreeDES_CBC_Mode_KeyString;

            crypt.SetEncodedKey(keyHex, "hex");
        }
Beispiel #5
0
        public void Configure(Crypt2 crypt)
        {
            crypt.UnlockComponent("Anything for 30-day trial.");


            //  Attention: use "blowfish2" for the algorithm name:
            crypt.CryptAlgorithm = "blowfish2";

            //  CipherMode may be "ecb", "cbc", or "cfb"
            crypt.CipherMode = "cbc";

            //  KeyLength (in bits) may be a number between 32 and 448.
            //  128-bits is usually sufficient.  The KeyLength must be a
            //  multiple of 8.
            crypt.KeyLength = 128;

            //  The padding scheme determines the contents of the bytes
            //  that are added to pad the result to a multiple of the
            //  encryption algorithm's block size.  Blowfish has a block
            //  size of 8 bytes, so encrypted output is always
            //  a multiple of 8.
            crypt.PaddingScheme = 0;

            //  EncodingMode specifies the encoding of the output for
            //  encryption, and the input for decryption.
            //  It may be "hex", "url", "base64", or "quoted-printable".
            crypt.EncodingMode = "hex";

            //  An initialization vector is required if using CBC or CFB modes.
            //  ECB mode does not use an IV.
            //  The length of the IV is equal to the algorithm's block size.
            //  It is NOT equal to the length of the key.
            const string ivHex = "0001020304050607";

            crypt.SetEncodedIV(ivHex, "hex");

            //  The secret key must equal the size of the key.  For
            //  256-bit encryption, the binary secret key is 32 bytes.
            //  For 128-bit encryption, the binary secret key is 16 bytes.
            var keyHex = Keys.Blowfish_CBC_KeyString;

            crypt.SetEncodedKey(keyHex, "hex");
        }
Beispiel #6
0
        public static string GenerateMac()
        {
            Crypt2 crypt = new Crypt2();

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

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

            //  Specify 3DES for the encryption algorithm:
            crypt.CryptAlgorithm = "3des";

            //  CipherMode may be "ecb" or "cbc"
            crypt.CipherMode = "cbc";

            //  KeyLength must be 192.  3DES is technically 168-bits;
            //  the most-significant bit of each key byte is a parity bit,
            //  so we must indicate a KeyLength of 192, which includes
            //  the parity bits.
            crypt.KeyLength = 192;

            //  The padding scheme determines the contents of the bytes
            //  that are added to pad the result to a multiple of the
            //  encryption algorithm's block size.  3DES has a block
            //  size of 8 bytes, so encrypted output is always
            //  a multiple of 8.
            crypt.PaddingScheme = 0;

            //  EncodingMode specifies the encoding of the output for
            //  encryption, and the input for decryption.
            //  It may be "hex", "url", "base64", or "quoted-printable".
            crypt.EncodingMode = "hex";

            //  An initialization vector is required if using CBC or CFB modes.
            //  ECB mode does not use an IV.
            //  The length of the IV is equal to the algorithm's block size.
            //  It is NOT equal to the length of the key.
            string ivHex = "0001020304050607";

            crypt.SetEncodedIV(ivHex, "hex");

            //  The secret key must equal the size of the key.  For
            //  3DES, the key must be 24 bytes (i.e. 192-bits).
            string keyHex = "000102030405060708090A0B0C0D0E0F0001020304050607";

            crypt.SetEncodedKey(keyHex, "hex");

            //  Encrypt a string...
            //  The input string is 44 ANSI characters (i.e. 44 bytes), so
            //  the output should be 48 bytes (a multiple of 8).
            //  Because the output is a hex string, it should
            //  be 96 characters long (2 chars per byte).
            string encStr = crypt.EncryptStringENC("The quick brown fox jumps over the lazy dog.");

            Console.WriteLine(encStr);

            //  Now decrypt:
            string decStr = crypt.DecryptStringENC(encStr);

            Console.WriteLine(decStr);
            return(decStr);
        }