Audiovox P965 Datový list Strana 100

  • Stažení
  • Přidat do mých příruček
  • Tisk
  • Strana
    / 280
  • Tabulka s obsahem
  • KNIHY
  • Hodnocené. / 5. Na základě hodnocení zákazníků
Zobrazit stránku 99
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++) {
Zobrazit stránku 99
1 2 ... 95 96 97 98 99 100 101 102 103 104 105 ... 279 280

Komentáře k této Příručce

Žádné komentáře