आयात java.io.FileInputStream; आयात java.io.ByteArrayOutputStream;
सार्वजनिक वर्ग FileHashStream { // एक नई पद्धति है कि एक नए बाइट सरणी प्रदान करेगा लिखते हैं, और जहां यह आम तौर पर एक इनपुट स्ट्रीम
public static byte[] read(InputStream is) throws Exception
{
String path = /* type in the absolute path for the 'commons-codec-1.10-bin.zip' */;
// must need a Byte buffer
byte[] buf = new byte[1024 * 16]
// we will use 16 kilobytes
int len = 0;
// we need a new input stream
FileInputStream is = new FileInputStream(path);
// use the buffer to update our "MessageDigest" instance
while(true)
{
len = is.read(buf);
if(len < 0) break;
md.update(buf, 0, len);
}
// close the input stream
is.close();
// call the "digest" method for obtaining the final hash-result
byte[] ret = md.digest();
System.out.println("Length of Hash: " + ret.length);
for(byte b : ret)
{
System.out.println(b + ", ");
}
String compare = "49276d206b696c6c696e6720796f757220627261696e206c696b65206120706f69736f6e6f7573206d757368726f6f6d";
String verification = Hex.encodeHexString(ret);
System.out.println();
System.out.println("===")
System.out.println(verification);
System.out.println("Equals? " + verification.equals(compare));
}
से पढ़ता}
स्रोत
2016-12-27 04:25:17
SHA128 का उपयोग कर यदि आप 'की कोशिश करो एक adruino करने के लिए स्ट्रिंग भेज रहे हैं। यह उलटा है; लेकिन मुझे नहीं पता कि आपको Arduino पर उस कोड की आवश्यकता होगी या नहीं। –