SHA256

SHA-256 (256 bit) is part of SHA-2 set of cryptographic hash functions, designed by the U.S. National Security Agency (NSA) and published in 2001 by the NIST as a U.S. Federal Information Processing Standard (FIPS). A hash function is an algorithm that transforms (hashes) an arbitrary set of data elements, such as a text file, into a single fixed length value (the hash). The computed hash value may then be used to verify the integrity of copies of the original data without providing any means to derive said original data. Irreversible, a hash value may be freely distributed, stored and used for comparative purposes. SHA stands for Secure Hash Algorithm. SHA-2 includes a significant number of changes from its predecessor.

For example,let’s say  we have a plain text “Selam”,you can use different programing lanuage to encrypt it via SHA256.

For PHP:

$hash_str=hash("sha256","Selam");

For C#:

    public static string SHA256Encrypt(string str)              
    {                  
    System.Security.Cryptography.SHA256 s256 = new System.Security.Cryptography.SHA256Managed();                  
    byte[] byte1;                  
    byte1 = s256.ComputeHash(Encoding.Default.GetBytes(str));                  
    s256.Clear();                  
    return Convert.ToBase64String(byte1);              
    }
    
    Console.write(SHA256Encrypt("Selam"));

For JAVA:

import java.security.MessageDigest;

public class Test{
	public static void main(String[] args) {	
		String t= "Selam";
		try {
			MessageDigest md = MessageDigest.getInstance("SHA-256");
			md.update(t.getBytes(""));
			for(byte b:md.digest())
				System.out.format("%02X",b);			
		} catch (Exception e) {			
			e.printStackTrace();
		}
	}
}

Leave a Reply

Close Menu