### Developer Guide

### SHA2 Hash Function

FraudLabs Pro uses SHA2 to hash the sensitive values, such as, email\_hash, username\_hash, password\_hash and card\_hash. User is required to hash these values prior to API request using the sample codes given below, otherwise the API will returns you the error.

### Online Hash Generator

To confirm you have implemented the hashing correctly, you can compare the result with our hash generator.

### Sample Codes

## PHP

&lt;?php

function

fraudlabspro\_hash

(

$s

)

\{

$hash

=

'fraudlabspro\_'

.

$s

;

for

(

$i

=

0

;

$i

&lt;

65536

;

$i

\+\+

)

\{

$hash

=

sha1

(

'fraudlabspro\_'

.

$hash

)

;

\}

$hash2

=

hash

(

'sha256'

,

$hash

)

;

return

$hash2

;

\}

?&gt;

## Java

import

java

.

security

.

MessageDigest

;

import

java

.

util

.

Formatter

;

public

class

main

\{

public

static

String

SHA1

(

String

s

)

throws

Exception

\{

MessageDigest

sha1

=

MessageDigest

.

getInstance

(

"SHA1"

)

;

Formatter

formatter

=

new

Formatter

(

)

;

sha1

.

update

(

s

.

getBytes

(

)

)

;

byte

\[

\]

hash

=

sha1

.

digest

(

)

;

for

(

byte

b

:

hash

)

\{

formatter

.

format

(

"%02x"

,

b

)

;

\}

return

formatter

.

toString

(

)

;

\}

public

static

String

fraudlabspro\_hash

(

String

s

)

throws

Exception

\{

Integer

i

=

0

;

String

hash

=

"fraudlabspro\_"

\+

s

;

for

(

i

=

0

;

i

&lt;

65536

;

i

\+\+

)

\{

hash

=

SHA1

(

"fraudlabspro\_"

\+

hash

)

;

\}

MessageDigest

sha256

=

MessageDigest

.

getInstance

(

"SHA-256"

)

;

byte

\[

\]

hashBytes

=

sha256

.

digest

(

hash

.

getBytes

(

)

)

;

StringBuilder

hash2

=

new

StringBuilder

(

)

;

for

(

byte

b

:

hashBytes

)

\{

hash2

.

append

(

String

.

format

(

"%02x"

,

b

)

)

;

\}

return

hash2

.

toString

(

)

;

\}

\}

## VB .NET

Imports

System

Imports

System

.

Security

.

Cryptography

Imports

System

.

Text

Public

Function

fraudlabspro\_hash

(

ByVal

s

As

String

)

As

String

Dim

i

As

Integer

=

0

Dim

hash

As

String

=

"fraudlabspro\_"

\+

s

For

i

=

1

To

65536

hash

=

ComputeSHA1Hash

(

"fraudlabspro\_"

\+

hash

)

Next

Using

mysha

=

SHA256

.

Create

(

)

Dim

inputBytes

As

Byte

(

)

=

Encoding

.

UTF8

.

GetBytes

(

hash

)

Dim

hashBytes

As

Byte

(

)

=

mysha

.

ComputeHash

(

inputBytes

)

Dim

hash2

As

New

StringBuilder

(

)

For

Each

b

As

Byte

In

hashBytes hash2

.

AppendFormat

(

"\{0:x2\}"

,

b

)

Next

Return

hash2

.

ToString

(

)

End

Using

End

Function

Public

Function

ComputeSHA1Hash

(

ByVal

s

As

String

)

As

String

Dim

bytes

(

)

As

Byte

Dim

x

As

String

=

""

Using

mysha

=

SHA1

.

Create

(

)

bytes

=

Encoding

.

ASCII

.

GetBytes

(

s

)

bytes

=

mysha

.

ComputeHash

(

bytes

)

For

Each

b

As

Byte

In

bytes x

\+

=

b

.

ToString

(

"x2"

)

Next

Return

x

End

Using

End

Function

## C\#

using

System

.

Security

.

Cryptography

;

using

System

.

Text

;

public

string

fraudlabspro\_hash

(

string

s

)

\{

int

i

=

0

;

string

hash

=

"fraudlabspro\_"

\+

s

;

for

(

i

=

1

;

i

&lt;=

65536

;

i

\+\+

)

\{

hash

=

ComputeSHA1Hash

(

"fraudlabspro\_"

\+

hash

)

;

\}

using

(

SHA256

mysha

=

SHA256

.

Create

(

)

)

\{

byte

\[

\]

inputBytes

=

Encoding

.

UTF8

.

GetBytes

(

hash

)

;

byte

\[

\]

hashBytes

=

mysha

.

ComputeHash

(

inputBytes

)

;

StringBuilder

hash2

=

new

StringBuilder

(

)

;

foreach

(

byte

b

in

hashBytes

)

\{

hash2

.

AppendFormat

(

"\{0:x2\}"

,

b

)

;

\}

return

hash2

.

ToString

(

)

;

\}

\}

public

string

ComputeSHA1Hash

(

string

s

)

\{

string

x

=

""

;

using

(

SHA1

mysha

=

SHA1

.

Create

(

)

)

\{

byte

\[

\]

bytes

=

Encoding

.

ASCII

.

GetBytes

(

s

)

;

bytes

=

mysha

.

ComputeHash

(

bytes

)

;

foreach

(

byte

b

in

bytes

)

\{

x

\+=

b

.

ToString

(

"x2"

)

;

\}

return

x

;

\}

\}

## Python

import

hashlib

def

fraudlabspro\_hash

(

s

)

:

hash

=

"fraudlabspro\_"

\+

s

for

i

in

range

(

65536

)

:

hash

=

hashlib

.

sha1

(

(

"fraudlabspro\_"

\+

hash

)

.

encode

(

'utf-8'

)

)

.

hexdigest

(

)

hash2

=

hashlib

.

sha256

(

hash

.

encode

(

)

)

.

hexdigest

(

)

return

hash2