]> git.proxmox.com Git - mirror_edk2.git/blame - Tools/Source/FrameworkWizard/src/org/tianocore/frameworkwizard/far/FarMd5.java
[Wizard- Far Install/Create]
[mirror_edk2.git] / Tools / Source / FrameworkWizard / src / org / tianocore / frameworkwizard / far / FarMd5.java
CommitLineData
5a24e806 1/** @file\r
2 \r
3 The file is used to caculate file MD5 value.\r
4 \r
5 Copyright (c) 2006, Intel Corporation\r
6 All rights reserved. This program and the accompanying materials\r
7 are licensed and made available under the terms and conditions of the BSD License\r
8 which accompanies this distribution. The full text of the license may be found at\r
9 http://opensource.org/licenses/bsd-license.php\r
10 \r
11 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
12 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
13 \r
14 **/\r
15package org.tianocore.frameworkwizard.far;\r
16\r
17import java.io.File;\r
18import java.io.FileInputStream;\r
19import java.security.MessageDigest;\r
20\r
21public class FarMd5 {\r
22\r
23 static public String md5(File file) throws Exception {\r
24 byte[] buffer = new byte[(int) file.length()];\r
25 FileInputStream fInput = new FileInputStream(file);\r
26 fInput.read(buffer);\r
27 fInput.close();\r
28 return md5(buffer);\r
29\r
30 }\r
31\r
32 static public String md5(byte[] buffer) throws Exception {\r
33 MessageDigest md = MessageDigest.getInstance("MD5");\r
34 byte[] md5 = md.digest(buffer);\r
96531299 35 return new String(String.format("%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x", md5[0], md5[1], md5[2], md5[3], md5[4],\r
5a24e806 36 md5[5], md5[6], md5[7], md5[8], md5[9], md5[10], md5[11], md5[12], md5[13],\r
37 md5[14], md5[15]));\r
38\r
39 }\r
40}\r