Beispiel #1
0
        public string Encrypt()
        {
            DirectoryInfo di = new DirectoryInfo(CertFileName);
            var           cryptographyHelper = new CryptographyHelper();
            var           certificate        = cryptographyHelper.GetX509Certificate(CertFileName);

            return(cryptographyHelper.Encrypt(certificate, ToString()));
        }
Beispiel #2
0
        public static Token Decrypt(string encryptedToken)
        {
            var cryptographyHelper = new CryptographyHelper();
            var certificate        = cryptographyHelper.GetX509Certificate(CertFileName);
            var decrypted          = cryptographyHelper.Decrypt(certificate, encryptedToken);

            // Splitting it to dictionary
            // [UserId=someguidvalue;Ip=127.0.0.1]
            var dictionary = decrypted.Split(';').Select(part => part.Split('=')).ToDictionary(split => split[0], split => split[1]);

            return(new Token(dictionary["UserId"], dictionary["Ip"]));
        }