如何在60天后过期申请 [英] How to expire a application after 60 days

查看:61
本文介绍了如何在60天后过期申请的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好

朋友我想在60天后过期申请。所以我想要一个从数据库接受开始日期和结束日期(与用户机器当前日期无关)的功能,它计算剩余天数并向用户发送消息,应用程序将过期。



提前致谢。 :)



我的尝试:



不知道该怎么办...



提前致谢。 :)

hello
friend i want expire the application after 60 days. so i want a function which accept the start date and end date (doesn't matter user machine current date) from the data base its calculate the remaining days and gives message to the user and application will be expire .

Thanks in advance. :)

What I have tried:

don't know what to do...

Thanks in advance. :)

推荐答案

为此使用DAT或类似文件(或者你可以填入数据库)。

当程序启动时检查DAT文件或DB值。

- 如果它是空白填充今天的日期

- 如果它不是空白,你有一个约会的日期。



这是一个简单的过程。以前公司的软件使用变量来在设定的日期使程序到期。
Use a DAT or similar file for this (or you could stuff in a DB).
When program starts check the DAT file or DB value.
- If it is blank populate with today's date
- If it isn't blank, you have a date to work with.

This is the simple process. A former company's software used a variant to expire the program on a set date.


解决方案1将起作用,但任何人都可以看到日期,因此加密它会更好。请参阅此处的示例:使用C#加密和解密数据 [使用C#加密和解密数据 ]



以下是使用配置文件存储数据的示例: .NET配置文件的原因,位置和方式 [ ^ ]



这是我的示例代码,使用硬件支持的加密形式更好/更快:

Solution 1 will work, but the date would be visible to anyone, so it would be better to encrypt it. See example here: Encrypt and Decrypt Data with C#[Encrypt and Decrypt Data with C#]

Here is an example of using configuration files to store your data: Why, Where, and How of .NET Configuration Files[^]

Here is my example code, it's better / faster to use a form of encryption that is supported by hardware:
// Put these lines in your Form or Program:
string encryptedString = Encrypt.EncryptStringAes(DateTime.Now.ToString(), "My secret code");
Debug.Print(encryptedString);

string decryptedString = Encrypt.DecryptStringAes(encryptedString, "My secret code");
Debug.Print(decryptedString);

// Put this in a Class library file:
namespace Test
{
    using System;
    using System.IO;
    using System.Security.Cryptography;
    using System.Text;

    /// <summary>
    /// Encrypt or decrypt using AES Rijndael encryption.
    /// </summary>
    public class Encrypt
    {
        // Change this to your secret key code:
        private static byte[] salt   = Encoding.ASCII.GetBytes("0123456789");

        /// <summary>
        /// Encrypt the given string using AES.  
        /// The string can be decrypted using DecryptStringAES().
        /// The sharedSecret parameters must match.
        /// </summary>
        /// <param name="plainText">The text to encrypt.</param>
        /// <param name="sharedSecret">A password used to generate a key for encryption.</param>
        /// <returns>The encrypted string.</returns>
        public static string EncryptStringAes(string plainText, string sharedSecret)
        {
            if (string.IsNullOrEmpty(plainText))
            {
                throw new ArgumentNullException("plainText");
            }

            if (string.IsNullOrEmpty(sharedSecret))
            {
                throw new ArgumentNullException("sharedSecret");
            }

            string outStr;                              // Encrypted string to return
            RijndaelManaged aesAlg = null;              // RijndaelManaged object used to encrypt the data.

            try
            {
                // generate the key from the shared secret and the salt
                var key = new Rfc2898DeriveBytes(sharedSecret, salt);

                // Create a RijndaelManaged object
                aesAlg = new RijndaelManaged();
                aesAlg.Key = key.GetBytes(aesAlg.KeySize / 8);

                // Create a decryptor to perform the stream transform.
                var encryptor = aesAlg.CreateEncryptor(aesAlg.Key, aesAlg.IV);

                // Create the streams used for encryption.
                using (var msEncrypt = new MemoryStream())
                {
                    // prepend the IV
                    msEncrypt.Write(BitConverter.GetBytes(aesAlg.IV.Length), 0, sizeof(int));
                    msEncrypt.Write(aesAlg.IV, 0, aesAlg.IV.Length);
                    using (var csEncrypt = new CryptoStream(msEncrypt, encryptor, CryptoStreamMode.Write))
                    {
                        using (var swEncrypt = new StreamWriter(csEncrypt))
                        {
                            swEncrypt.Write(plainText);
                        }
                    }

                    outStr = Convert.ToBase64String(msEncrypt.ToArray());
                }
            }
            finally
            {
                // Clear the RijndaelManaged object.
                if (aesAlg != null)
                {
                    aesAlg.Clear();
                }
            }

            // Return the encrypted bytes from the memory stream.
            return outStr;
        }

        /// <summary>
        /// Decrypt the given string, assumes the string was encrypted using EncryptStringAes() using an identical sharedSecret.
        /// </summary>
        /// <param name="cipherText">The text to decrypt.</param>
        /// <param name="sharedSecret">A password used to generate a key for decryption.</param>
        /// <returns>The decrypted string.</returns>
        public static string DecryptStringAes(string cipherText, string sharedSecret)
        {
            if (string.IsNullOrEmpty(cipherText))
            {
                throw new ArgumentNullException("cipherText");
            }

            if (string.IsNullOrEmpty(sharedSecret))
            {
                throw new ArgumentNullException("sharedSecret");
            }

            // Declare the RijndaelManaged object used to decrypt the data.
            RijndaelManaged aesAlg = null;

            // The decrypted text.
            string plaintext;

            try
            {
                // generate the key from the shared secret and the salt
                var key = new Rfc2898DeriveBytes(sharedSecret, salt);

                // Create the streams used for decryption.                
                byte[] bytes = Convert.FromBase64String(cipherText);
                using (var msDecrypt = new MemoryStream(bytes))
                {
                    // Create a RijndaelManaged object with the specified key and IV.
                    aesAlg = new RijndaelManaged();
                    aesAlg.Key = key.GetBytes(aesAlg.KeySize / 8);

                    // Get the initialization vector from the encrypted stream
                    aesAlg.IV = ReadByteArray(msDecrypt);

                    // Create a decryptor to perform the stream transform.
                    var decryptor = aesAlg.CreateDecryptor(aesAlg.Key, aesAlg.IV);

                    using (var csDecrypt = new CryptoStream(msDecrypt, decryptor, CryptoStreamMode.Read))
                    {
                        using (var srDecrypt = new StreamReader(csDecrypt))
                        {
                            // Read the decrypted bytes from the decrypting stream and place them in a string.
                            plaintext = srDecrypt.ReadToEnd();
                        }
                    }
                }
            }
            finally
            {
                // Clear the RijndaelManaged object.
                if (aesAlg != null)
                {
                    aesAlg.Clear();
                }
            }

            return plaintext;
        }

        private static byte[] ReadByteArray(Stream s)
        {
            byte[] rawLength = new byte[sizeof(int)];

            if (s.Read(rawLength, 0, rawLength.Length) != rawLength.Length)
            {
                throw new SystemException("Stream did not contain properly formatted byte array");
            }

            byte[] buffer = new byte[BitConverter.ToInt32(rawLength, 0)];

            if (s.Read(buffer, 0, buffer.Length) != buffer.Length)
            {
                throw new SystemException("Did not read byte array properly");
            }

            return buffer;
        }
    }
}


这篇关于如何在60天后过期申请的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆