@Test public void testCreateApikey() { String nick = "testnick"; String apikey = np.createApikey(nick); assertEquals("1cf7cd3896b7f93f73e4f689d8fb780bdb90a0e7689a6a86d74e2ea41ab9e224", apikey); }
protected String createApikey(String nick) { try { MessageDigest digest = MessageDigest.getInstance("SHA-256"); digest.reset(); byte[] byteData = digest.digest(nick.getBytes("UTF-8")); System.out.println(byteData); StringBuffer sb = new StringBuffer(); for (int i = 0; i < byteData.length; i++) { sb.append(Integer.toString((byteData[i] & 0xff) + 0x100, 16).substring(1)); } return sb.toString(); } catch (NoSuchAlgorithmException err) { logger.error("Algorithm for hashing does not exist."); } catch (UnsupportedEncodingException err) { logger.error("No such encoding (UTF-8)."); } return null; }
NPPlugin implements PluginWithDependencies { protected String createApikey(String nick) { try { MessageDigest digest = MessageDigest.getInstance("SHA-256"); digest.reset(); byte[] byteData = digest.digest(nick.getBytes("UTF-8")); System.out.println(byteData); StringBuffer sb = new StringBuffer(); for (int i = 0; i < byteData.length; i++) { sb.append(Integer.toString((byteData[i] & 0xff) + 0x100, 16).substring(1)); } return sb.toString(); } catch (NoSuchAlgorithmException err) { logger.error("Algorithm for hashing does not exist."); } catch (UnsupportedEncodingException err) { logger.error("No such encoding (UTF-8)."); } return null; } }
NPPlugin implements PluginWithDependencies { protected String createApikey(String nick) { try { MessageDigest digest = MessageDigest.getInstance("SHA-256"); digest.reset(); byte[] byteData = digest.digest(nick.getBytes("UTF-8")); System.out.println(byteData); StringBuffer sb = new StringBuffer(); for (int i = 0; i < byteData.length; i++) { sb.append(Integer.toString((byteData[i] & 0xff) + 0x100, 16).substring(1)); } return sb.toString(); } catch (NoSuchAlgorithmException err) { logger.error("Algorithm for hashing does not exist."); } catch (UnsupportedEncodingException err) { logger.error("No such encoding (UTF-8)."); } return null; } NPPlugin(); }
NPPlugin implements PluginWithDependencies { protected String createApikey(String nick) { try { MessageDigest digest = MessageDigest.getInstance("SHA-256"); digest.reset(); byte[] byteData = digest.digest(nick.getBytes("UTF-8")); System.out.println(byteData); StringBuffer sb = new StringBuffer(); for (int i = 0; i < byteData.length; i++) { sb.append(Integer.toString((byteData[i] & 0xff) + 0x100, 16).substring(1)); } return sb.toString(); } catch (NoSuchAlgorithmException err) { logger.error("Algorithm for hashing does not exist."); } catch (UnsupportedEncodingException err) { logger.error("No such encoding (UTF-8)."); } return null; } NPPlugin(); @Override String[] getDependencies(); @Override void loadDependency(Plugin plugin); @Override String getDescription(); @Override void addEventDistributor(EventDistributor eventDistributor); @Override void addWand(Wand wand); @Override void incomingEvent(Event e); }
NPPlugin implements PluginWithDependencies { protected String createApikey(String nick) { try { MessageDigest digest = MessageDigest.getInstance("SHA-256"); digest.reset(); byte[] byteData = digest.digest(nick.getBytes("UTF-8")); System.out.println(byteData); StringBuffer sb = new StringBuffer(); for (int i = 0; i < byteData.length; i++) { sb.append(Integer.toString((byteData[i] & 0xff) + 0x100, 16).substring(1)); } return sb.toString(); } catch (NoSuchAlgorithmException err) { logger.error("Algorithm for hashing does not exist."); } catch (UnsupportedEncodingException err) { logger.error("No such encoding (UTF-8)."); } return null; } NPPlugin(); @Override String[] getDependencies(); @Override void loadDependency(Plugin plugin); @Override String getDescription(); @Override void addEventDistributor(EventDistributor eventDistributor); @Override void addWand(Wand wand); @Override void incomingEvent(Event e);  }