List of usage examples for javax.crypto BadPaddingException printStackTrace
public void printStackTrace()
From source file:net.navasoft.madcoin.backend.services.security.Encrypter.java
/** * The main method./* w ww.j a va 2s . c o m*/ * * @param args * the arguments * @since 5/08/2014, 08:57:04 PM */ public static void main(String[] args) { try { String raw = "drandx/$2a$14$nv0yHyxSwnROrYnevt66TOx5pVCBr58wFiMOjkZKQScciwsiC18xG"; Encrypter x = new Encrypter("Click-n-Done2014", "madcoins"); String crypted = x.encrypt(raw); System.out.println("este es el token" + crypted); String dec; dec = x.decrypt(crypted); System.out.println(raw.split("/")[1]); System.out.println(dec.split("/")[1]); System.out.println( raw + (BCrypt.checkpw(raw.split("/")[1], dec.split("/")[1]) ? " muchooooo!" : " es mentira")); } catch (BadPaddingException e) { e.printStackTrace(); } }
From source file:com.alta189.deskbin.util.DesEncrypter.java
public String encrypt(String str) { try {// www . j a v a 2 s .c om // Encode the string into bytes using utf-8 byte[] utf8 = str.getBytes("UTF8"); // Encrypt byte[] enc = ecipher.doFinal(utf8); // Encode bytes to base64 to get a string return Base64.encodeBase64String(enc); } catch (javax.crypto.BadPaddingException e) { e.printStackTrace(); } catch (IllegalBlockSizeException e) { e.printStackTrace(); } catch (UnsupportedEncodingException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } return null; }
From source file:com.alta189.deskbin.util.DesEncrypter.java
public String decrypt(String str) { try {/*from w w w. j a v a2s .c om*/ // Decode base64 to get bytes byte[] dec = Base64.decodeBase64(str); // Decrypt byte[] utf8 = dcipher.doFinal(dec); // Decode using utf-8 return new String(utf8, "UTF8"); } catch (javax.crypto.BadPaddingException e) { e.printStackTrace(); } catch (IllegalBlockSizeException e) { e.printStackTrace(); } catch (UnsupportedEncodingException e) { e.printStackTrace(); } catch (java.io.IOException e) { e.printStackTrace(); } return null; }
From source file:net.navasoft.madcoin.backend.services.rest.impl.SessionService.java
/** * Gets the user info.//from w ww. j a v a 2 s. c om * * @param userRequested * the user requested * @return the user info * @since 31/08/2014, 07:37:51 PM */ public UserInfoSuccessResponseVO getUserInfo(SuccessRequestVO userRequested) { userRequested.processValues(this); generatedToken = String.valueOf(userRequested.extractValue("generatedToken")); try { if (tokenGenerator.validate(generatedToken.replace("%2B", "+").replace("%2F", "/"))) { UserInfoSuccessResponseVO response = new UserInfoSuccessResponseVO(); EndUsersPK key = new EndUsersPK(); key.setAppUsername( ((UserDetails) SecurityContextHolder.getContext().getAuthentication().getPrincipal()) .getUsername()); EndUsers user = accessor.getByLogicalId(key); response.setFullName(user.getUserNames() + " " + user.getLastName()); response.setEmail(user.getEmail()); response.setToken(generatedToken); return response; } else { return null; } } catch (BadPaddingException e) { e.printStackTrace(); return null; } }
From source file:net.navasoft.madcoin.backend.services.rest.impl.TokenVerifierFilter.java
/** * Do filter./*from w w w.j a va 2s . c o m*/ * * @param request * the request * @param response * the response * @param chain * the chain * @throws IOException * Signals that an I/O exception has occurred. * @throws ServletException * the servlet exception * @since 8/09/2014, 10:28:12 AM */ @Override public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException { Map<String, String[]> parms = request.getParameterMap(); if (parms.containsKey("allowanceToken")) { String token = parms.get("allowanceToken")[0]; try { if (tokenUtils.validate(token)) { UserDetails userDetails = tokenUtils.getUserFromToken(token); UsernamePasswordAuthenticationToken authentication = new UsernamePasswordAuthenticationToken( userDetails.getUsername(), userDetails.getPassword()); authentication.setDetails( new WebAuthenticationDetailsSource().buildDetails((HttpServletRequest) request)); SecurityContextHolder.getContext().setAuthentication(userManager.authenticate(authentication)); } } catch (BadPaddingException e) { } catch (AuthenticationException e) { } } else if (parms.containsKey("workerToken")) { String token = parms.get("workerToken")[0]; try { if (providerTokenUtils.validate(token)) { UserDetails userDetails = providerTokenUtils.getUserFromToken(token); UsernamePasswordAuthenticationToken authentication = new UsernamePasswordAuthenticationToken( userDetails.getUsername(), userDetails.getPassword()); authentication.setDetails( new WebAuthenticationDetailsSource().buildDetails((HttpServletRequest) request)); SecurityContextHolder.getContext() .setAuthentication(providerManager.authenticate(authentication)); } } catch (BadPaddingException e) { e.printStackTrace(); } catch (AuthenticationException e) { e.printStackTrace(); } } chain.doFilter(request, response); }