c# ------------------------------------------------------------------------------------
private void button6_Click(object sender, EventArgs e)
{
OpenFileDialog openFileDialog1 = new OpenFileDialog();
openFileDialog1.Filter = "Checksum Files|*.*";
openFileDialog1.Title = "SHA256 체크를 하실 파일을 선택하세요";
if (openFileDialog1.ShowDialog() == System.Windows.Forms.DialogResult.OK)
{
string checksum = "";
string path = openFileDialog1.FileName;
using (System.IO.FileStream stream = System.IO.File.OpenRead(path))
{
System.Security.Cryptography.SHA256Managed sha = new System.Security.Cryptography.SHA256Managed();
byte[] bytes = sha.ComputeHash(stream);
checksum = BitConverter.ToString(bytes).Replace("-", String.Empty);
}
MessageBox.Show(checksum.ToUpper());
}
}
java---------------------------------------------------------------------------------
import java.io.FileInputStream;
import java.security.MessageDigest;
public class SHACheckSumExample
{
public static void main(String[] args)throws Exception
{
MessageDigest md = MessageDigest.getInstance("SHA-256");
FileInputStream fis = new FileInputStream("c:\\J2060408462350.png");
byte[] dataBytes = new byte[1024];
int nread = 0;
while ((nread = fis.read(dataBytes)) != -1) {
md.update(dataBytes, 0, nread);
};
byte[] mdbytes = md.digest();
//convert the byte to hex format method 1
StringBuffer sb = new StringBuffer();
for (int i = 0; i < mdbytes.length; i++) {
sb.append(Integer.toString((mdbytes[i] & 0xff) + 0x100, 16).substring(1));
}
System.out.println("Hex format : " + sb.toString());
}
}
javac SHACheckSumExample.java
java SHACheckSumExample