/** * Decrypted data and return result * * @param {string} str XOR encrypted data * @param {string} pword password for decryption * @return {string} plain text */ public string pfDecryption(string str, string pword) { try { // encode special character "+", "/" and "=" in str string val = WebUtility.UrlDecode(str); byte[] sVal = System.Convert.FromBase64String(val); string bVal = Xor.Pfxor(System.Text.Encoding.UTF8.GetString(sVal), pword); return(WebUtility.UrlDecode(bVal)); } catch (Exception e) { Console.WriteLine("Decryption failed, {0} ", e); return(""); } }
/** * Encrypt data and return result * * @param {string} str Plain text * @param {string} pword password for encryption * @return {string} Cypher text */ public string pfEncryption(string str, string pword) { try { string val = WebUtility.UrlEncode(str); val = Xor.Pfxor(val, pword); byte[] sval = System.Text.Encoding.UTF8.GetBytes(val); // encode special character "+", "/" and "=" in base64 result return(WebUtility.UrlEncode(System.Convert.ToBase64String(sval))); } catch (Exception e) { Console.WriteLine("Encryption failed, {0} ", e); return(""); } }