예제 #1
0
        //the way a code is encrypted may be changed by class inheritors
        //but adding the _magic is unique using the | separator and _magic
        protected static string GenerateCode(string plainText)
        {
            var log   = ClassLogger.Create(typeof(AuthorizationCode));
            var dblog = DebugOnlyLogger.Create(log);

            var cryptText = PWCrypto.Encrypt(plainText, _pwd);

            dblog.InfoFormat(GeneratedCodeMsgFormat, plainText);

            return(cryptText);
        }
예제 #2
0
        public static T DecryptDeserialize(string t, string pass)
        {
            Contract.Requires(!string.IsNullOrEmpty(t));
            Contract.Requires(!string.IsNullOrWhiteSpace(pass));

            var log = ClassLogger.Create(typeof(EncryptedObject <T>));

            string p = PWCrypto.Decrypt(t, pass);

            log.InfoFormat("Decrypting object {0}", p);
            T token = JsonConvert.DeserializeObject <T>(p);

            return(token);
        }
예제 #3
0
        public static string EncryptSerialize(T token, string pass)
        {
            Contract.Requires(null != token);
            Contract.Requires(!string.IsNullOrWhiteSpace(pass));

            var log = ClassLogger.Create(typeof(EncryptedObject <T>));


            string s = JsonConvert.SerializeObject(token);

            log.InfoFormat("Securing object {0}", s);
            string c = PWCrypto.Encrypt(s, pass);

            return(c);
        }
예제 #4
0
        //decrypt a code, this method may be overriten by inheritors with other ways to decrypt
        protected static string DecryptCode(string authCode)
        {
            var plain = PWCrypto.Decrypt(authCode, _pwd);

            return(plain);
        }