Datasheet
API in Java
97
}
Hasher.java
Helper functions to perform some tasks
package libAPI;
/*
* Helper.java
*
* Created on 08 June 2007, 11:25
*
* To change this template, choose Tools | Template Manager
* and open the template in the editor.
*/
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
/**
*
* @author janisk
*/
public class Hasher {
/**
* makes MD5 hash of string for use with RouterOS API
* @param s - variable to make hacsh from
* @return
*/
static public String hashMD5(String s) {
String md5val = "";
MessageDigest algorithm = null;
try {
algorithm = MessageDigest.getInstance("MD5");
} catch (NoSuchAlgorithmException nsae) {
System.out.println("Cannot find digest algorithm");
System.exit(1);
}
byte[] defaultBytes = new byte[s.length()];
for (int i = 0; i < s.length(); i++) {
defaultBytes[i] = (byte) (0xFF & s.charAt(i));
}
algorithm.reset();
algorithm.update(defaultBytes);
byte messageDigest[] = algorithm.digest();
StringBuffer hexString = new StringBuffer();
for (int i = 0; i < messageDigest.length; i++) {










