/** * Encodes binary data using the base64 algorithm but does not chunk the output. * * @param binaryData * binary data to encode * @return Base64 characters */ public static byte[] encodeBase64(byte[] binaryData) { return encodeBase64(binaryData, false); }
/** * Encodes binary data using the base64 algorithm and chunks the encoded output into 76 character blocks * * @param binaryData * binary data to encode * @return Base64 characters chunked in 76 character blocks */ public static byte[] encodeBase64Chunked(byte[] binaryData) { return encodeBase64(binaryData, true); }
/** * Encodes a byte[] containing binary data, into a byte[] containing characters in the Base64 alphabet. * * @param pArray * a byte array containing binary data * @return A byte array containing only Base64 character data */ public byte[] encode(byte[] pArray) { return encodeBase64(pArray, false); }
public static String computeXoauth(String username, String authToken) throws UnsupportedEncodingException { String formattedAuthenticationString = String.format(XOAUTH_FORMAT, username, authToken); byte[] base64encodedAuthenticationString = Base64.encodeBase64(formattedAuthenticationString.getBytes()); return new String(base64encodedAuthenticationString, US_ASCII); } }
/** * Encode to a byte64-encoded integer according to crypto * standards such as W3C's XML-Signature * * @param bigInt a BigInteger * @return A byte array containing base64 character data * @throws NullPointerException if null is passed in */ public static byte[] encodeInteger(BigInteger bigInt) { if (bigInt == null) { throw new NullPointerException("encodeInteger called with null parameter"); } return encodeBase64(toIntegerBytes(bigInt), false); }
return Base64.encodeBase64(plainCRAM.getBytes());
private List<ImapResponse> saslAuthPlain() throws IOException, MessagingException { String command = Commands.AUTHENTICATE_PLAIN; String tag = sendCommand(command, false); readContinuationResponse(tag); String credentials = "\000" + settings.getUsername() + "\000" + settings.getPassword(); byte[] encodedCredentials = Base64.encodeBase64(credentials.getBytes()); outputStream.write(encodedCredentials); outputStream.write('\r'); outputStream.write('\n'); outputStream.flush(); try { return responseParser.readStatusResponse(tag, command, getLogId(), null); } catch (NegativeImapResponseException e) { throw handleAuthenticationFailure(e); } }
private void authPlain() throws MessagingException { executeSimpleCommand("AUTH PLAIN"); try { byte[] encodedBytes = Base64.encodeBase64(("\000" + settings.getUsername() + "\000" + settings.getPassword()).getBytes()); executeSimpleCommand(new String(encodedBytes), true); } catch (Pop3ErrorResponse e) { throw new AuthenticationFailedException( "POP3 SASL auth PLAIN authentication failed: " + e.getMessage(), e); } }
@Test public void open_withAuthTypePlainAndPlainAuthCapability_performsPlainAuth() throws Exception { settings.setAuthType(AuthType.PLAIN); MockPop3Server server = new MockPop3Server(); server.output("+OK POP3 server greeting"); server.expect("AUTH"); server.output("+OK Listing of supported mechanisms follows"); server.output("PLAIN"); server.output("CRAM-MD5"); server.output("EXTERNAL"); server.output("."); server.expect("CAPA"); server.output("+OK Listing of supported mechanisms follows"); server.output("PLAIN"); server.output("CRAM-MD5"); server.output("EXTERNAL"); server.output("."); server.expect("AUTH PLAIN"); server.output("+OK"); server.expect(new String(Base64.encodeBase64(("\000"+username+"\000"+password).getBytes()))); server.output("+OK"); startServerAndCreateOpenConnection(server); server.verifyConnectionStillOpen(); server.verifyInteractionCompleted(); }
@Test public void open_withAuthTypePlainAndPlainAuthCapabilityAndInvalidPasswordResponse_throwsException() throws Exception { settings.setAuthType(AuthType.PLAIN); MockPop3Server server = new MockPop3Server(); server.output("+OK POP3 server greeting"); server.expect("AUTH"); server.output("+OK Listing of supported mechanisms follows"); server.output("PLAIN"); server.output("CRAM-MD5"); server.output("EXTERNAL"); server.output("."); server.expect("CAPA"); server.output("+OK Listing of supported mechanisms follows"); server.output("PLAIN"); server.output("CRAM-MD5"); server.output("EXTERNAL"); server.output("."); server.expect("AUTH PLAIN"); server.output("+OK"); server.expect(new String(Base64.encodeBase64(("\000"+username+"\000"+password).getBytes()))); server.output("-ERR"); try { startServerAndCreateOpenConnection(server); fail("Expected auth failure"); } catch (AuthenticationFailedException ignored) {} server.verifyInteractionCompleted(); }