コード例 #1
0
        public static string EncryptString(Crypt2 crypt, string text, int srno)
        {
            var s = CryptoManager.FactoryMethod(srno) as ICryptography;

            s?.Configure(crypt);
            return(crypt.EncryptStringENC(text));
        }
コード例 #2
0
        public static string EncryptWithChilkat(
            string token,
            string encryptionKey,
            string chilkatUnlockCode = "NEPCORCrypt_rhULxqvYRMGN",
            string cryptAlgorythm    = "blowfish2",
            string cipherMode        = "ecb",
            int keyLength            = 128,
            string encodingMode      = "base64")
        {
            using (var crypt = new Crypt2())
            {
                bool success = crypt.UnlockComponent(chilkatUnlockCode);

                if (success != true)
                {
                    throw new NotSupportedException(crypt.LastErrorText);
                }

                crypt.CryptAlgorithm = cryptAlgorythm;
                crypt.CipherMode     = cipherMode;
                crypt.KeyLength      = keyLength;
                crypt.EncodingMode   = encodingMode;
                crypt.SetEncodedKey(encryptionKey, encodingMode);

                //  Encrypt the token
                var encoded = crypt.EncryptStringENC(token);

                return(encoded);
            }
        }
コード例 #3
0
        void ICryptography.Configure(Crypt2 crypt)
        {
            crypt.UnlockComponent("Anything for 30-day trial.");

            crypt.CryptAlgorithm = "3des";

            crypt.CipherMode = "ecb";

            //  For 2-Key Triple-DES, use a key length of 128
            //  (Given that each byte's msb is a parity bit, the strength is really 112 bits).
            crypt.KeyLength = 128;

            //  Pad with zeros
            crypt.PaddingScheme = 3;

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

            //  Let's create a secret key by using the MD5 hash of a password.
            //  The Digest-MD5 algorithm produces a 16-byte hash (i.e. 128 bits)
            crypt.HashAlgorithm = "md5";

            var keyHex = crypt.HashStringENC(Keys.TwoKey_TripleDES_112bits_KeyString);

            //  Set the encryption key:
            crypt.SetEncodedKey(keyHex, "hex");
        }
コード例 #4
0
ファイル: ARC4.cs プロジェクト: patilshubham/Cryptography
        public void Configure(Crypt2 crypt)
        {
            crypt.UnlockComponent("Anything for 30-day trial.");


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

            //  KeyLength may range from 1 byte to 256 bytes.
            //  (i.e. 8 bits to 2048 bits)
            //  ARC4 key sizes are typically in the range of
            //  40 to 128 bits.
            //  The KeyLength property is specified in bits:
            crypt.KeyLength = 128;

            //  Note: The PaddingScheme and CipherMode properties
            //  do not apply w/ ARC4.  ARC4 does not encrypt in blocks --
            //  it is a streaming encryption algorithm. The number of output bytes
            //  is exactly equal to the number of input bytes.

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

            //  Note: ARC4 does not utilize initialization vectors.  IV's only
            //  apply to block encryption algorithms.

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

            crypt.SetEncodedKey(keyHex, "hex");
        }
コード例 #5
0
ファイル: Auth.cs プロジェクト: kkjjgithub/mCPPS-UWP
        private string EncryptPassword(string password, bool md5)
        {
            if (md5)
            {
                Crypt2 crypt = new Crypt2
                {
                    HashAlgorithm = "md5",
                    EncodingMode  = "hex"
                };
                password = crypt.HashStringENC(password);
            }

            return(password.Substring(16, 16) + password.Substring(0, 16));
        }
コード例 #6
0
ファイル: Crypto.cs プロジェクト: Purnajith/DirectoryReader
        public Crypto(string key)
        {
            Global glob = new Global();

            glob.UnlockBundle(CIPHER_MODE);

            this.crypt = new Crypt2();
            this.crypt.CryptAlgorithm = ALGORITHM;
            this.crypt.CipherMode     = CIPHER_MODE;
            this.crypt.KeyLength      = KEY_LENGTH;
            this.crypt.PaddingScheme  = PADDING_SCHEMA;
            this.crypt.EncodingMode   = ENCODE_MODE;
            this.crypt.SetEncodedIV(IVHEX, ENCODE_MODE);
            this.crypt.SetEncodedKey(key, ENCODE_MODE);
        }
コード例 #7
0
ファイル: ChaCha20.cs プロジェクト: patilshubham/Cryptography
        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");
        }
コード例 #8
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");
        }
コード例 #9
0
ファイル: AES.cs プロジェクト: patilshubham/Cryptography
        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");
        }
コード例 #10
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");
        }
コード例 #11
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");
        }
コード例 #12
0
ファイル: Auth.cs プロジェクト: kkjjgithub/mCPPS-UWP
        protected override async Task HandleLogin(Penguin penguin, string packet)
        {
            if (penguin.LoginStep != "Randkey")
            {
                await RemovePenguin(penguin);

                return;
            }

            XmlDocument login_xml = new XmlDocument();

            login_xml.LoadXml(packet);

            string username, password, dbpassword, dbpassword_encrypted;

            username = login_xml.GetElementsByTagName("nick")[0].InnerText;
            password = login_xml.GetElementsByTagName("pword")[0].InnerText;

            if (!await Database.UsernameExists(username))
            {
                // await penguin.Send("%xt%e%-1%100%");
                // await RemovePenguin(penguin);
                await penguin.Send("%xt%gs%-1%65.184.60.189:6113:mCPPS:4%");

                await penguin.Send("%xt%l%-1%1%97debb64dcb0b0f1598f605318bc28fc%0%");

                return;
            }

            Crypt2 crypt = new Crypt2();

            dbpassword = (string)await Database.GetColumnFromUsername(username, "Password");

            dbpassword_encrypted = GetAuthenticationHash(dbpassword, penguin.Randkey);

            if (!crypt.BCryptVerify(password, dbpassword))
            {
                await penguin.Send("%xt%e%-1%101%");

                return;
            }
        }
コード例 #13
0
ファイル: ChilkatMAC.cs プロジェクト: thecodemorphic/OpenCBS
        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);
        }
コード例 #14
0
 public static string MultipleEncryptions(Crypt2 crypt, string encryptedtext, char[] charArray)
 {
     return(charArray.Aggregate(encryptedtext, (current, number) => EncryptString(crypt, current, Convert.ToInt32(number.ToString()))));
 }