List of usage examples for org.apache.commons.codec.binary Base32 Base32
public Base32()
From source file:cz.alej.michalik.totp.util.TOTP.java
/** * Ukzka TOTP pro zprvu "12345678901234567890" */// w w w . j av a 2s . c om public static void main(String[] args) { // GEZDGNBVGY3TQOJQGEZDGNBVGY3TQOJQ v base32 String secret = "12345678901234567890"; System.out.printf("Heslo je: %s \nV Base32 to je: %s\n", secret, new Base32().encodeToString(secret.getBytes())); TOTP t = new TOTP(secret.getBytes()); System.out.printf("%s\n", t); while (true) { int time = Integer.valueOf(new SimpleDateFormat("ss").format(new Date())); if (time % 30 == 0) { System.out.printf("%s\n", t); } try { Thread.sleep(1000); } catch (InterruptedException e) { e.printStackTrace(); } } }
From source file:es.logongas.fpempresa.security.SecureKeyGenerator.java
public static String getSecureKey() { try {/*from w w w . j a v a 2s . c om*/ Base32 base32 = new Base32(); KeyGenerator keyGen = KeyGenerator.getInstance("AES"); keyGen.init(keyLength); SecretKey secretKey = keyGen.generateKey(); byte[] encoded = secretKey.getEncoded(); return base32.encodeAsString(encoded); } catch (Exception ex) { throw new RuntimeException(ex); } }
From source file:crocserver.app.CrocSecurity.java
public static String createSecret() { byte[] bytes = new byte[10]; new SecureRandom().nextBytes(bytes); return new Base32().encodeAsString(bytes); }
From source file:dualcontrol.DualControlDigest.java
public static String digestBase32(char[] chars) { try {// w ww. j a v a2s. c o m return new Base32().encodeAsString(digest(chars)); } catch (Exception e) { throw new RuntimeException(e); } }
From source file:aaf.vhr.crypto.GoogleAuthenticator.java
/** * Generate a random secret key. This must be saved by the server and associated with the * users account to verify the code displayed by Google Authenticator. * The user must register this secret on their device. * @return secret key//from w ww . j a v a2 s . co m */ public static String generateSecretKey() { try { SecureRandom sr = SecureRandom.getInstance("SHA1PRNG"); Base32 codec = new Base32(); byte[] buffer = new byte[10]; sr.nextBytes(buffer); byte[] bEncodedKey = codec.encode(buffer); String encodedKey = new String(bEncodedKey); return encodedKey; } catch (NoSuchAlgorithmException e) { e.printStackTrace(); throw new RuntimeException(e.getMessage()); } }
From source file:co.mitro.twofactor.TwoFactorCodeChecker.java
public static boolean checkCode(String secret, long code, long timeMsec) { Base32 codec = new Base32(); byte[] decodedKey = codec.decode(secret); long t = (timeMsec / 1000L) / 30L; for (int i = -WINDOW_SIZE; i <= WINDOW_SIZE; ++i) { long hash; try {//from www . j a v a2s.c om hash = computeHash(decodedKey, t + i); } catch (Exception e) { e.printStackTrace(); throw new RuntimeException(e.getMessage()); } if (hash == code) { return true; } } return false; }
From source file:co.mitro.twofactor.TwoFactorSecretGenerator.java
public static String generateSecretKey() { byte[] buffer = new byte[SECRET_SIZE]; secureRandom.nextBytes(buffer);/*w w w .ja va 2 s. c o m*/ Base32 codec = new Base32(); byte[] secretKey = Arrays.copyOf(buffer, SECRET_SIZE); byte[] bEncodedKey = codec.encode(secretKey); String encodedKey = new String(bEncodedKey, Charsets.UTF_8); return encodedKey; }
From source file:com.zxlim.totp.TOTP.java
public static final TOTP getInstance(final int window, final String encodedSecret) throws IllegalWindowSizeException { if (window >= 1 && window <= 10) { Base32 base32 = new Base32(); final byte[] secret = base32.decode(encodedSecret); return new TOTP(window, secret, encodedSecret); } else {//from w w w. j av a2s. c o m throw new IllegalWindowSizeException("Window size provided not allowed: " + window); } }
From source file:crocserver.app.CrocSecurity.java
public static String createCode(byte[] secret, String string, long value) throws Exception { Mac mac = createHmac(secret); mac.update(string.getBytes());//ww w . ja v a 2s . com return new Base32().encodeAsString(mac.doFinal(toByteArray(value))); }
From source file:com.fortinet.qcdb.AscenLinkKey.java
private String do_md5(String sn, String func, int argc, String[] argv) { try {/* w w w. j a v a 2s. co m*/ MessageDigest m = MessageDigest.getInstance("MD5"); m.update("DEMO_TTL".getBytes()); m.update(sn.getBytes()); m.update("*%#($a3EB".getBytes()); m.update(func.getBytes()); for (int i = 0; i < argc; i++) m.update(argv[i].getBytes()); Base32 b32 = new Base32(); byte[] k = b32.encode(m.digest()); StringBuilder sb = new StringBuilder(); for (int i = 0; i < 25; i++) { if (i > 0 && i % 5 == 0) sb.append("-"); sb.append((char) k[i]); } return sb.toString(); } catch (Exception e) { e.printStackTrace(); return null; } }