List of usage examples for org.apache.shiro.codec Hex decode
public static byte[] decode(char[] data) throws IllegalArgumentException
From source file:cn.com.rexen.ext.shiro.web.filter.authc.ForwardedX509AuthenticationFilter.java
License:Open Source License
private String readHexSerialNumberFromString(String input) { return Hex.encodeToString(Hex.decode(input)); // FIXME Upstream Hex implementation is not char encoding safe, fix it there }
From source file:com.enioka.jqm.webui.shiro.JpaRealm.java
License:Open Source License
private SimpleAccount getUser(String login) { EntityManager em = null;/* ww w .j a va 2 s . c om*/ try { em = Helpers.getEm(); RUser user = em.createQuery("SELECT u FROM RUser u WHERE UPPER(u.login) = UPPER(:l)", RUser.class) .setParameter("l", login).getSingleResult(); // Credential is a password - in token, it is as a char array SimpleAccount res = new SimpleAccount(user.getLogin(), user.getPassword(), getName()); if (user.getExpirationDate() != null) { res.setCredentialsExpired(user.getExpirationDate().before(Calendar.getInstance())); } else { // No limit = never expires res.setCredentialsExpired(false); } if (user.getHashSalt() != null) { res.setCredentialsSalt(ByteSource.Util.bytes(Hex.decode(user.getHashSalt()))); } else { res.setCredentialsSalt(null); } res.setLocked(user.getLocked()); // Roles for (RRole r : user.getRoles()) { res.addRole(r.getName()); for (RPermission p : r.getPermissions()) { res.addStringPermission(p.getName()); } } return res; } catch (NoResultException e) { // No such user in realm return null; } catch (RuntimeException e) { e.printStackTrace(); throw e; } finally { em.close(); } }
From source file:com.once.crosscloud.utils.EndecryptUtils.java
License:Apache License
/** * 16 //from w w w .j a v a 2 s . c o m * @param cipherText * @return */ public static String decryptHex(String cipherText) { return new String(Hex.decode(cipherText)); }
From source file:com.once.crosscloud.utils.EndecryptUtils.java
License:Apache License
public static void main(String[] args) { String password = "admin"; String cipherText = encrytHex(password); System.out.println(password + "hex?" + cipherText); String decrptPassword = decryptHex(cipherText); System.out.println(cipherText + "hex??" + decrptPassword); String cipherText_base64 = encrytBase64(password); System.out.println(password + "base64?" + cipherText_base64); String decrptPassword_base64 = decryptBase64(cipherText_base64); System.out.println(cipherText_base64 + "base64??" + decrptPassword_base64); String h64 = H64.encodeToString(password.getBytes()); System.out.println(h64);// w w w . j ava 2s . co m String salt = "7road"; String cipherText_md5 = new Md5Hash(password, salt, 4).toHex(); System.out.println(password + "md5?" + cipherText_md5); System.out.println(generateKey()); System.out.println("=========================================================="); AesCipherService aesCipherService = new AesCipherService(); aesCipherService.setKeySize(128); Key key = aesCipherService.generateNewKey(); String aes_cipherText = aesCipherService.encrypt(password.getBytes(), key.getEncoded()).toHex(); System.out.println(password + " aes" + aes_cipherText); String aes_mingwen = new String( aesCipherService.decrypt(Hex.decode(aes_cipherText), key.getEncoded()).getBytes()); System.out.println(aes_cipherText + " aes" + aes_mingwen); }
From source file:com.zht.common.shiro.util.EndecryptUtils.java
License:Apache License
/** * 16 //from ww w . j a va 2 s. com * @param cipherText * @return */ public static String decryptHex(String cipherText) { if (cipherText == null) { return null; } return new String(Hex.decode(cipherText)); }
From source file:org.atteo.moonshine.shiro.database.DatabaseRealm.java
License:Apache License
@Override @Transactional/*from ww w.jav a 2s . c o m*/ protected AuthenticationInfo doGetAuthenticationInfo(AuthenticationToken token) throws AuthenticationException { String principal = (String) token.getPrincipal(); Account loginAccount = accountRepository.findOne(principal); if (loginAccount == null) { return null; } SimplePrincipalCollection principalCollection = new SimplePrincipalCollection(loginAccount.getLogin(), getName()); SimpleAuthenticationInfo info = new SimpleAuthenticationInfo(principalCollection, loginAccount.getHashedPassword(), new SimpleByteSource(Hex.decode(loginAccount.getSalt()))); return info; }
From source file:org.cherchgk.security.realms.HibernateRealm.java
License:Apache License
@Override protected AuthenticationInfo doGetAuthenticationInfo(AuthenticationToken authenticationToken) throws AuthenticationException { UsernamePasswordToken token = (UsernamePasswordToken) authenticationToken; String username = token.getUsername(); User user = getUser(username);/*from w ww. ja v a 2s . c o m*/ if (user.getBlocked()) { throw new DisabledAccountException("Account for user [" + username + "] is locked"); } return new SimpleAuthenticationInfo(username, ByteSource.Util.bytes(Hex.decode(user.getPassword())), ByteSource.Util.bytes(Hex.decode(user.getPasswordSalt())), getName()); }
From source file:org.graylog2.security.AESTools.java
License:Open Source License
public static String decrypt(String cipherText, String encryptionKey, String salt) { try {//from w ww.j a va 2 s . co m Cipher cipher = Cipher.getInstance("AES/CBC/ISO10126Padding", "SunJCE"); SecretKeySpec key = new SecretKeySpec(encryptionKey.getBytes("UTF-8"), "AES"); cipher.init(Cipher.DECRYPT_MODE, key, new IvParameterSpec(salt.getBytes("UTF-8"))); return new String(cipher.doFinal(Hex.decode(cipherText)), "UTF-8"); } catch (Exception e) { LOG.error("Could not decrypt value.", e); } return null; }
From source file:org.obiba.mica.micaConfig.service.MicaConfigService.java
License:Open Source License
public String decrypt(String encrypted) { try {// w w w.j av a 2 s . c o m ByteSource decrypted = cipherService.decrypt(Hex.decode(encrypted), getSecretKey()); return CodecSupport.toString(decrypted.getBytes()); } catch (CryptoException e) { logger.warn(String.format("Someone tried to use an invalid key [%s]", encrypted)); throw new IllegalArgumentException("Given key is invalid", e); } }
From source file:org.obiba.mica.micaConfig.service.MicaConfigService.java
License:Open Source License
private byte[] getSecretKey() { return Hex.decode(getOrCreateMicaConfig().getSecretKey()); }