コード例 #1
0
ファイル: DesTest.cs プロジェクト: n873/CSharpCryptography
        public void DecryptString()
        {
            var encrypted       = DesUtility.EncryptStringToBytes_Des(originalText, Key, IV);
            var decryptedString = DesUtility.DecryptStringFromBytes_Des(encrypted, Key, IV);

            Assert.AreEqual(originalText, decryptedString);
        }
コード例 #2
0
        public int GetDecodedUserAvatar(string code, string encodeKey)
        {
            try
            {
                var content  = DesUtility.DecryptDES(code, encodeKey);
                var datas    = content.Split('|');
                var dateTime = new DateTime(long.Parse(datas[0]));

                if ((DateTime.Now - dateTime).TotalSeconds > 15)
                {
                    return(-1);//指定秒后失效
                }

                var accountId = int.Parse(datas[1]);
                return(accountId);
            }
            catch
            {
                return(-1);
            }
        }
コード例 #3
0
 public string GetDecodedContent(string content, string encodeKey)
 {
     return(DesUtility.DecryptDES(content, encodeKey));
 }
コード例 #4
0
        private void button6_Click(object sender, EventArgs e)
        {
            DesUtility des = new DesUtility();

            textBox1.Text = des.Decrypt(textBox2.Text.Trim());
        }
コード例 #5
0
ファイル: DesTest.cs プロジェクト: n873/CSharpCryptography
        public void EncryptString()
        {
            var encrypted = DesUtility.EncryptStringToBytes_Des(originalText, Key, IV);

            Assert.AreNotEqual(originalText, encrypted.ToString());
        }
コード例 #6
0
        public string GetEncodedUserAvatar(int accountId, string encodeKey)
        {
            var content = $"{DateTime.Now.Ticks}|{accountId}";

            return(DesUtility.EncryptDES(content, encodeKey));
        }
コード例 #7
0
        /// <summary>
        /// 通用解密
        /// </summary>
        /// <param name="str"></param>
        /// <returns></returns>
        public string CommonDecrypt(string str)
        {
            var content = DesUtility.EncryptDES(str, BASE_ENCRYPT_ENCODING_KEY);

            return(str.Split('|')[0]);
        }
コード例 #8
0
        /// <summary>
        /// 通用加密
        /// </summary>
        /// <param name="str"></param>
        /// <returns></returns>
        public string CommonEncrypt(string str)
        {
            var content = $"{str}|{BASE_ENCRYPT_ENCODING_KEY}";

            return(DesUtility.EncryptDES(content, BASE_ENCRYPT_ENCODING_KEY));
        }