• Code
  • Tags
  • Users
  • Titles
  • Log in
  • Feedback
  • FAQ
Share Code
Welcome to ForkCan.com

ForkCan is all about sharing code in a social way.

Discuss, debate or argue with other devs about their or your own code.

Give other devs feedback or make a Fork (Make a better version of a shared code).

Rate the code, if you use the code mark it as used so others can see if the shared code is used by someone.

Help each other to be better devs and to be more productive.


Features not working yet:

Flag a post


QR Code

Tiny Url

http://4kcan.com/s/MTg1

Related Code
Some useful extensions to String
Fork of Some useful extensions to String
Extension for string.Format(...)
Extension method to create a delimited string from a IEnumerable<T>
Parsing string to enum, extension method
Method to hash passwords
GreaterThen LessThan extenstion methods to Int type
Fork of Extension method to create a delimited string from a IEnumerable<T>

To, FromBase64 and ToHash (Flash code friendly) Extension

Three methods for String, ToBase64 string and FromBase64 string and a ToHash with saltkey

5
423 2 0 0 0 0

public static class StringExtension
    {
        public static string ToBase64(this string x)
        {
            var toEncodeAsBytes = Encoding.ASCII.GetBytes(x);
            var returnValue = Convert.ToBase64String(toEncodeAsBytes);
            return returnValue;
        }

        public static string FromBase64(this string x)
        {
            var toEncodeAsBytes = Convert.FromBase64String(x);
            var returnValue = Encoding.ASCII.GetString(toEncodeAsBytes);
            return returnValue;
        }

        public static string ToHash(this string x,string saltKey)
        {
            var keyStringBuilder = new StringBuilder();
            keyStringBuilder.Append(x);
            keyStringBuilder.Append(saltKey);

            var originalBytes = Encoding.Default.GetBytes(keyStringBuilder.ToString());
            var hashedDataBytes = new MD5CryptoServiceProvider().ComputeHash(originalBytes);

            var hexHashBuilder = new StringBuilder();
            foreach (byte b in hashedDataBytes)
            {
                hexHashBuilder.AppendFormat("{0:x2}", b);
            }
            byte[] encbuff = Encoding.UTF8.GetBytes(hexHashBuilder.ToString());
            return Convert.ToBase64String(encbuff);
        }
    }

Share: twitter | facebook   Action: used | fork | flag

base64

Mark 'base64' tag as 'like'

Mark 'base64' tag as 'ignore'

c#

Mark 'c#' tag as 'like'

Mark 'c#' tag as 'ignore'

extension

Mark 'extension' tag as 'like'

Mark 'extension' tag as 'ignore'

hash

Mark 'hash' tag as 'like'

Mark 'hash' tag as 'ignore'

string

Mark 'string' tag as 'like'

Mark 'string' tag as 'ignore'


 @johannormen "Code Contributor"
1.24k
July 13, 2010 9:11 AM

Fork

 To, FromBase64 and ToHash (Flash code friendly) Extension -  @johannormen Tuesday 13, 2010 9:11 AM


0 Feedback


You must log in before you can give any feedback


0 Discussion(s)

Newest Oldest

You must log in before you can post a comment

Squeed
Made by: Fredrik Normén 2010