Visto 2.115 veces.

Clase para codificar en md5 base64 y decodificar base64 en c# sharp

[csharp]
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Security.Cryptography;

namespace xavirobot {
class Algoritmo {
public static string MD5Encode(string Value) {
System.Security.Cryptography.MD5CryptoServiceProvider x = new System.Security.Cryptography.MD5CryptoServiceProvider();
byte[] data = System.Text.Encoding.ASCII.GetBytes(Value);
data = x.ComputeHash(data);
string ret = “”;
for (int i = 0; i < data.Length; i++) ret += data[i].ToString("x2").ToLower(); return ret; } public static string Base64Encode(string cadena) { byte[] cadenaByte = new byte[cadena.Length]; cadenaByte = System.Text.Encoding.UTF8.GetBytes(cadena); string encodedCadena = Convert.ToBase64String(cadenaByte); return encodedCadena; } public static string Base64Decode(string cadena) { var encoder = new System.Text.UTF8Encoding(); var utf8Decode = encoder.GetDecoder(); byte[] cadenaByte = Convert.FromBase64String(cadena); int charCount = utf8Decode.GetCharCount(cadenaByte, 0, cadenaByte.Length); char[] decodedChar = new char[charCount]; utf8Decode.GetChars(cadenaByte, 0, cadenaByte.Length, decodedChar, 0); string result = new String(decodedChar); return result; } } } [/csharp]

Deja un comentario

Tu dirección de correo electrónico no será publicada. Los campos obligatorios están marcados con *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code class="" title="" data-url=""> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong> <pre class="" title="" data-url=""> <span class="" title="" data-url="">