//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);
        }
Example #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);
        }
Example #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);
        }
        //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);
        }