public static byte[] decodeIfNeeded(byte[] recv) { boolean arrayByteBase64 = Base64.isArrayByteBase64(recv); if (LOG.isDebugEnabled() && arrayByteBase64) { LOG.debug("Data only contains Base64 alphabets only so try to decode the data."); } return arrayByteBase64 ? Base64.decodeBase64(recv) : recv; } }
@Test public void generateRandomSecretKey() { AesCipher cipher = new AesCipher(null); String key = cipher.generateRandomSecretKey(); assertThat(StringUtils.isNotBlank(key)).isTrue(); assertThat(Base64.isArrayByteBase64(key.getBytes())).isTrue(); }
@Test public void encrypt() throws Exception { AesCipher cipher = new AesCipher(pathToSecretKey()); String encryptedText = cipher.encrypt("this is a secret"); assertThat(StringUtils.isNotBlank(encryptedText)).isTrue(); assertThat(Base64.isArrayByteBase64(encryptedText.getBytes())).isTrue(); }
public static byte[] decodeIfNeeded(byte[] recv) { boolean arrayByteBase64 = Base64.isArrayByteBase64(recv); if (DEBUG_LOG_ENABLED && arrayByteBase64) { LOG.debug("Data only contains Base64 alphabets only so try to decode the data."); } return arrayByteBase64 ? Base64.decodeBase64(recv) : recv; } }
public static byte[] decodeIfNeeded(byte[] recv) { boolean arrayByteBase64 = Base64.isArrayByteBase64(recv); if (DEBUG_LOG_ENABLED && arrayByteBase64) { LOG.debug("Data only contains Base64 alphabets only so try to decode the data."); } return arrayByteBase64 ? Base64.decodeBase64(recv) : recv; } }
public static byte[] decodeIfNeeded(byte[] recv) { boolean arrayByteBase64 = Base64.isArrayByteBase64(recv); if (LOG.isDebugEnabled() && arrayByteBase64) { LOG.debug("Data only contains Base64 alphabets only so try to decode the data."); } return arrayByteBase64 ? Base64.decodeBase64(recv) : recv; } }
/** * Decodes a Base64 encoded String. Interprets bytes as UTF-8 encoded by * default. */ public static String decodeBase64(String pEncodedString) { try { byte[] encodedBytes = pEncodedString.getBytes("UTF-8"); // this is only a low protection, and don't say that the given bytes really base64. if (Base64.isArrayByteBase64(encodedBytes)) { return new String(Base64.decodeBase64(encodedBytes), "UTF-8"); } // is not base 64 encoded return pEncodedString; } catch (UnsupportedEncodingException e) { throw new IllegalStateException("UTF-8 encoding unknown!", e); } }
public String getUsername() { try { byte[] ticketArray = m_credentialText.getBytes("UTF-8"); SAMLTicket ticket; if (Base64.isArrayByteBase64(ticketArray)) { ticket = new SAMLTicket(StringUtils.decodeBase64(m_credentialText)); Subject subject = ticket.asSubject(""); for (Principal principal : subject.getPrincipals()) { if (principal instanceof UsernameIDPrincipal) { return ((UsernameIDPrincipal) principal).getName(); } } String ticketAsString = ticket.asString(); return (ticketAsString.length() > 40) ? ticketAsString.substring(0, 40) : ticketAsString; } } catch (UnsupportedEncodingException e) { // do nothing -> return ticket "as is" } catch (SAMLException e) { // do nothing -> return ticket "as is" } return m_credentialText; }
@Override protected void operateOnChildNode(Content node, InstallContext ctx) throws RepositoryException, TaskExecutionException { if (NodeTypes.User.NAME.equals(node.getNodeTypeName())) { String encodedPassword = node.getNodeData("pswd").getString(); if (StringUtils.isNotBlank(encodedPassword)) { byte[] pwdBytes; try { pwdBytes = encodedPassword.getBytes("UTF-8"); } catch (UnsupportedEncodingException e) { String message = node.getName() + " password could not be hashed. User might need to reset the password before logging again."; log.warn(message); ctx.warn(message); pwdBytes = encodedPassword.getBytes(); } if (Base64.isArrayByteBase64(pwdBytes)) { String pwd = new String(Base64.decodeBase64(pwdBytes)); String hashedPwd = SecurityUtil.getBCrypt(pwd); node.setNodeData("pswd", hashedPwd); } } } else { // AllChildrennodeOp is not recursive! for (Content child : node.getChildren(filter)) { operateOnChildNode(child, ctx); } } } }
if( !Base64.isArrayByteBase64( auth.getNonce().getBytes("UTF-8") ) ) { log.warn( "nonce not base64 encoded" ); return null;
if (Base64.isArrayByteBase64(cookieValue.getBytes())) { if (logger.isDebugEnabled()) { logger.debug("Remember-me cookie detected");
if (!Base64.isArrayByteBase64(nonce.getBytes())) { fail(request, response, new BadCredentialsException(messages.getMessage("DigestProcessingFilter.nonceEncoding",