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