1 people like it.

PHP compatible MD5 hash calculation

Calculate MD5 hash that can be used when interacting with a PHP-website. Note: MD5 has been cracked and shouldn't be used in new systems.

1: 
2: 
3: 
4: 
5: 
let phpMd5 (dataToHash:string) = 
    use md5 = new System.Security.Cryptography.MD5CryptoServiceProvider();
    let encodedBytes = dataToHash |> System.Text.ASCIIEncoding.Default.GetBytes |> md5.ComputeHash
    System.Text.RegularExpressions.Regex.Replace(
        System.BitConverter.ToString(encodedBytes), "-", "").ToLower()
val phpMd5 : dataToHash:string -> string

Full name: Script.phpMd5
val dataToHash : string
Multiple items
val string : value:'T -> string

Full name: Microsoft.FSharp.Core.Operators.string

--------------------
type string = System.String

Full name: Microsoft.FSharp.Core.string
val md5 : System.Security.Cryptography.MD5CryptoServiceProvider
namespace System
namespace System.Security
namespace System.Security.Cryptography
Multiple items
type MD5CryptoServiceProvider =
  inherit MD5
  new : unit -> MD5CryptoServiceProvider
  member Initialize : unit -> unit

Full name: System.Security.Cryptography.MD5CryptoServiceProvider

--------------------
System.Security.Cryptography.MD5CryptoServiceProvider() : unit
val encodedBytes : byte []
namespace System.Text
Multiple items
type ASCIIEncoding =
  inherit Encoding
  new : unit -> ASCIIEncoding
  member GetByteCount : chars:string -> int + 2 overloads
  member GetBytes : chars:char * charCount:int * bytes:byte * byteCount:int -> int + 2 overloads
  member GetCharCount : bytes:byte * count:int -> int + 1 overload
  member GetChars : bytes:byte * byteCount:int * chars:char * charCount:int -> int + 1 overload
  member GetDecoder : unit -> Decoder
  member GetEncoder : unit -> Encoder
  member GetMaxByteCount : charCount:int -> int
  member GetMaxCharCount : byteCount:int -> int
  member GetString : bytes:byte[] * byteIndex:int * byteCount:int -> string
  ...

Full name: System.Text.ASCIIEncoding

--------------------
System.Text.ASCIIEncoding() : unit
property System.Text.Encoding.Default: System.Text.Encoding
System.Text.Encoding.GetBytes(s: string) : byte []
System.Text.Encoding.GetBytes(chars: char []) : byte []
System.Text.Encoding.GetBytes(chars: char [], index: int, count: int) : byte []
System.Text.Encoding.GetBytes(chars: nativeptr<char>, charCount: int, bytes: nativeptr<byte>, byteCount: int) : int
System.Text.Encoding.GetBytes(s: string, charIndex: int, charCount: int, bytes: byte [], byteIndex: int) : int
System.Text.Encoding.GetBytes(chars: char [], charIndex: int, charCount: int, bytes: byte [], byteIndex: int) : int
System.Security.Cryptography.HashAlgorithm.ComputeHash(buffer: byte []) : byte []
System.Security.Cryptography.HashAlgorithm.ComputeHash(inputStream: System.IO.Stream) : byte []
System.Security.Cryptography.HashAlgorithm.ComputeHash(buffer: byte [], offset: int, count: int) : byte []
namespace System.Text.RegularExpressions
Multiple items
type Regex =
  new : pattern:string -> Regex + 1 overload
  member GetGroupNames : unit -> string[]
  member GetGroupNumbers : unit -> int[]
  member GroupNameFromNumber : i:int -> string
  member GroupNumberFromName : name:string -> int
  member IsMatch : input:string -> bool + 1 overload
  member Match : input:string -> Match + 2 overloads
  member Matches : input:string -> MatchCollection + 1 overload
  member Options : RegexOptions
  member Replace : input:string * replacement:string -> string + 5 overloads
  ...

Full name: System.Text.RegularExpressions.Regex

--------------------
System.Text.RegularExpressions.Regex(pattern: string) : unit
System.Text.RegularExpressions.Regex(pattern: string, options: System.Text.RegularExpressions.RegexOptions) : unit
System.Text.RegularExpressions.Regex.Replace(input: string, pattern: string, evaluator: System.Text.RegularExpressions.MatchEvaluator) : string
System.Text.RegularExpressions.Regex.Replace(input: string, pattern: string, replacement: string) : string
System.Text.RegularExpressions.Regex.Replace(input: string, pattern: string, evaluator: System.Text.RegularExpressions.MatchEvaluator, options: System.Text.RegularExpressions.RegexOptions) : string
System.Text.RegularExpressions.Regex.Replace(input: string, pattern: string, replacement: string, options: System.Text.RegularExpressions.RegexOptions) : string
type BitConverter =
  static val IsLittleEndian : bool
  static member DoubleToInt64Bits : value:float -> int64
  static member GetBytes : value:bool -> byte[] + 9 overloads
  static member Int64BitsToDouble : value:int64 -> float
  static member ToBoolean : value:byte[] * startIndex:int -> bool
  static member ToChar : value:byte[] * startIndex:int -> char
  static member ToDouble : value:byte[] * startIndex:int -> float
  static member ToInt16 : value:byte[] * startIndex:int -> int16
  static member ToInt32 : value:byte[] * startIndex:int -> int
  static member ToInt64 : value:byte[] * startIndex:int -> int64
  ...

Full name: System.BitConverter
System.BitConverter.ToString(value: byte []) : string
System.BitConverter.ToString(value: byte [], startIndex: int) : string
System.BitConverter.ToString(value: byte [], startIndex: int, length: int) : string

More information

Link:http://fssnip.net/7P6
Posted:1 years ago
Author:Tuomas Hietanen
Tags: hashing , md5 , php