Java Code Examples for org.apache.commons.codec.binary.Base64
The following code examples are extracted from open source projects. You can click to
vote up the examples that are useful to you.
Example 1
From project alfredo, under directory /alfredo/src/main/java/com/cloudera/alfredo/util/.
Source file: Signer.java

/** * Returns then signature of a string. * @param str string to sign. * @return the signature for the string. */ protected String computeSignature(String str){ try { MessageDigest md=MessageDigest.getInstance("SHA"); md.update(str.getBytes()); md.update(secret); byte[] digest=md.digest(); Base64 base64=new Base64(0); return base64.encodeToString(digest); } catch ( NoSuchAlgorithmException ex) { throw new RuntimeException("It should not happen, " + ex.getMessage(),ex); } }
Example 2
From project candlepin, under directory /src/test/java/org/candlepin/test/.
Source file: TestUtil.java

public static String xmlToBase64String(String xml){ Base64 encoder=new Base64(); byte[] bytes=encoder.encode(xml.getBytes()); StringBuilder buf=new StringBuilder(); for ( byte b : bytes) { buf.append((char)Integer.parseInt(Integer.toHexString(b),16)); } return buf.toString(); }
Example 3
From project cas, under directory /cas-server-core/src/test/java/org/jasig/cas/authentication/principal/.
Source file: GoogleAccountsServiceTests.java

protected static String encodeMessage(final String xmlString) throws IOException { byte[] xmlBytes=xmlString.getBytes("UTF-8"); ByteArrayOutputStream byteOutputStream=new ByteArrayOutputStream(); DeflaterOutputStream deflaterOutputStream=new DeflaterOutputStream(byteOutputStream); deflaterOutputStream.write(xmlBytes,0,xmlBytes.length); deflaterOutputStream.close(); Base64 base64Encoder=new Base64(); byte[] base64EncodedByteArray=base64Encoder.encode(byteOutputStream.toByteArray()); return new String(base64EncodedByteArray); }
Example 4
From project moji, under directory /src/main/java/fm/last/moji/local/.
Source file: Base64FileNamingStrategy.java

@Override public String domainForFileName(String fileName){ String encodedDomain=fileName.split("[-\\.]")[0]; Base64 base64=new Base64(-1); String domain=decode(base64,encodedDomain); return domain; }
Example 5
From project chililog-server, under directory /src/main/java/org/chililog/server/common/.
Source file: CryptoUtils.java

/** * <p> From a password, a number of iterations and a salt, returns the corresponding hash. </p> <p> If the salt is to be appended, this convention is used: <code>base64(hash(plainTextValue + salt)+salt)</code> </p> <p> If the salt is NOT to be appended, this convention is used: <code>base64(hash(plainTextValue + salt))</code> </p> * @param plainTextValue String The password to encrypt * @param salt byte[] The salt. If null, one will be created on your behalf. * @param appendSalt True if the salt is to be appended to hashed value. In this way, for convenience, the salt can be kept with the hash. Use this only if the hash is to be kept internal to this app. If the hash is to be sent to external systems, set this to false and store the hash internally. * @return String The hash password * @throws ChiliLogException if SHA-512 is not supported or UTF-8 is not a supported encoding algorithm */ public static String createSHA512Hash(String plainTextValue,byte[] salt,boolean appendSalt) throws ChiliLogException { try { if (plainTextValue == null) { throw new NullArgumentException("plainTextValue"); } if (salt == null) { throw new NullArgumentException("salt"); } byte[] plainTextBytes=plainTextValue.getBytes("UTF-8"); byte[] plainTextWithSaltBytes=new byte[plainTextBytes.length + salt.length]; for (int i=0; i < plainTextBytes.length; i++) { plainTextWithSaltBytes[i]=plainTextBytes[i]; } if (appendSalt) { for (int i=0; i < salt.length; i++) { plainTextWithSaltBytes[plainTextBytes.length + i]=salt[i]; } } MessageDigest digest=MessageDigest.getInstance("SHA-512"); digest.reset(); byte[] hashBytes=digest.digest(plainTextWithSaltBytes); byte[] hashWithSaltBytes=new byte[hashBytes.length + salt.length]; for (int i=0; i < hashBytes.length; i++) { hashWithSaltBytes[i]=hashBytes[i]; } for (int i=0; i < salt.length; i++) { hashWithSaltBytes[hashBytes.length + i]=salt[i]; } Base64 encoder=new Base64(1000,new byte[]{},false); return encoder.encodeToString(hashWithSaltBytes); } catch ( Exception ex) { throw new ChiliLogException(ex,"Error attempting to hash passwords. " + ex.getMessage()); } }
Example 6
From project collector, under directory /src/test/java/com/ning/metrics/collector/.
Source file: TestPerformance.java

private static String createThriftPayload() throws TException { final List<ThriftField> data=new ArrayList<ThriftField>(); data.add(ThriftField.createThriftField("Fuu",(short)1)); data.add(ThriftField.createThriftField(true,(short)2)); data.add(ThriftField.createThriftField(3.1459,(short)3)); return String.format("%s:%s",new DateTime().getMillis(),new Base64().encodeToString(new ThriftFieldListSerializer().createPayload(data))); }
Example 7
From project CoursesPortlet, under directory /courses-portlet-webapp/src/main/java/org/jasig/portlet/courses/dao/xml/.
Source file: HttpClientCoursesDaoImpl.java

/** * Get a request entity prepared for basic authentication. */ protected HttpEntity<?> getRequestEntity(PortletRequest request){ @SuppressWarnings("unchecked") Map<String,String> userInfo=(Map<String,String>)request.getAttribute(PortletRequest.USER_INFO); String username=userInfo.get(this.usernameKey); String password=userInfo.get(this.passwordKey); HttpHeaders requestHeaders=new HttpHeaders(); String authString=username.concat(":").concat(password); String encodedAuthString=new Base64().encodeToString(authString.getBytes()); requestHeaders.set("Authorization","Basic ".concat(encodedAuthString)); HttpEntity<?> requestEntity=new HttpEntity<Object>(requestHeaders); return requestEntity; }
Example 8
From project doorkeeper, under directory /core/src/main/java/net/dataforte/doorkeeper/authenticator/basic/.
Source file: BasicAuthenticator.java

/** * Basic Authentication * @param request The servlet request * @param response The servlet response * @param skipAuthentication If true the negotiation is only done if it is initiated by the client (MSIE post requests after successful NTLM SSP authentication). If false and the user has not been authenticated yet the client will be forced to send an authentication (server sends HttpServletResponse.SC_UNAUTHORIZED). * @return True if the negotiation is complete, otherwise false */ public AuthenticatorToken negotiate(HttpServletRequest request,HttpServletResponse response){ String msg=request.getHeader("Authorization"); try { if (msg != null && msg.startsWith("Basic ")) { if (log.isDebugEnabled()) { log.debug("Finalizing Basic Authentication"); } Base64 b64=new Base64(); String auth=new String(b64.decode(msg.substring(6)),"US-ASCII"); int index=auth.indexOf(':'); String username=(index != -1) ? auth.substring(0,index) : auth; String password=(index != -1) ? auth.substring(index + 1) : ""; index=username.indexOf('\\'); if (index == -1) index=username.indexOf('/'); username=(index != -1) ? username.substring(index + 1) : username; if (log.isDebugEnabled()) { log.debug("Username: " + username + " Password: "+ password); } return new PasswordAuthenticatorToken(username,password); } else { if (log.isDebugEnabled()) { log.debug("Initiating Basic Authentication"); } response.setHeader("WWW-Authenticate","Basic realm=\"" + realm + "\""); response.setStatus(HttpServletResponse.SC_UNAUTHORIZED); response.flushBuffer(); return new AuthenticatorToken(AuthenticatorState.NEGOTIATING); } } catch ( Exception e) { log.error("",e); } return new AuthenticatorToken(AuthenticatorState.NONE); }
Example 9
From project eventtracker, under directory /scribe/src/main/java/com/ning/metrics/eventtracker/.
Source file: ScribeSender.java

protected static String eventToLogEntryMessage(final Event event) throws IOException { byte[] payload=event.getSerializedEvent(); if (payload == null) { final ByteArrayOutputStream out=new ByteArrayOutputStream(); event.writeExternal(new ObjectOutputStream(out)); payload=out.toByteArray(); payload=new Base64().encode(payload); } final String scribePayload=new String(payload,CHARSET); return String.format("%s:%s",event.getEventDateTime().getMillis(),scribePayload); }
Example 10
From project hdiv, under directory /hdiv-core/src/main/java/org/hdiv/util/.
Source file: EncodingUtil.java

/** * The object <code>obj</code> is compressed, encrypted and coded in Base64. * @param obj Object to encrypt * @return Objet <code>obj</code> compressed, encrypted and coded in Base64 * @throws HDIVException if there is an error encoding object <code>data</code> * @see java.util.zip.GZIPOutputStream#GZIPOutputStream(java.io.OutputStream) * @see org.apache.commons.codec.net.URLCodec#encodeUrl(java.util.BitSet,byte[]) * @see org.apache.commons.codec.binary.Base64#encode(byte[]) */ public String encode64Cipher(Object obj){ try { ByteArrayOutputStream baos=new ByteArrayOutputStream(); OutputStream zos=new GZIPOutputStream(baos); ObjectOutputStream oos=new ObjectOutputStream(zos); oos.writeObject(obj); oos.close(); zos.close(); baos.close(); byte[] cipherData=this.session.getEncryptCipher().encrypt(baos.toByteArray()); byte[] encodedData=URLCodec.encodeUrl(null,cipherData); Base64 base64Codec=new Base64(); return new String(base64Codec.encode(encodedData),ZIP_CHARSET); } catch ( Exception e) { String errorMessage=HDIVUtil.getMessage("encode.message"); throw new HDIVException(errorMessage,e); } }
Example 11
From project httpClient, under directory /httpclient/src/main/java/org/apache/http/impl/auth/.
Source file: GGSSchemeBase.java

GGSSchemeBase(boolean stripPort){ super(); this.base64codec=new Base64(); this.state=State.UNINITIATED; this.stripPort=stripPort; }
Example 12
From project isohealth, under directory /Oauth/java/jmeter/jmeter/src/main/java/org/apache/jmeter/protocol/oauth/sampler/.
Source file: PrivateKeyReader.java

/** * Read the PEM file and convert it into binary DER stream * @return * @throws IOException */ private byte[] readKeyMaterial(String endMarker) throws IOException { String line=null; StringBuffer buf=new StringBuffer(); while ((line=server.readLine(fileName)) != null) { if (line.indexOf(endMarker) != -1) { return new Base64().decode(buf.toString().getBytes()); } buf.append(line.trim()); } throw new IOException("Invalid PEM file: No end marker"); }
Example 13
From project m2release-plugin, under directory /src/main/java/org/jvnet/hudson/plugins/m2release/nexus/.
Source file: StageClient.java

/** * Add the BASIC Authentication header to the HTTP connection. * @param conn the HTTP URL Connection */ private void addAuthHeader(HttpURLConnection conn){ try { String auth=username + ":" + password; String encodedAuth=new Base64().encodeToString(auth.getBytes("ISO-8859-1")).trim(); conn.setRequestProperty("Authorization","Basic " + encodedAuth); log.debug("Encoded Authentication is: " + encodedAuth); } catch ( UnsupportedEncodingException ex) { String msg="JVM does not conform to java specification. Mandatory CharSet ISO-8859-1 is not available."; log.error(msg); throw new RuntimeException(msg,ex); } }
Example 14
From project meaningfulweb, under directory /meaningfulweb-app/src/main/java/org/meaningfulweb/servlet/.
Source file: HtmlExtractorController.java

@RequestMapping(value="/bytes.json",method=RequestMethod.POST) public @ResponseBody Map extractContentFromBytes(@RequestBody ExtractForm extractForm,HttpServletRequest request,HttpServletResponse response){ Map errors=new HashMap(); String content=extractForm.getContent(); if (StringUtils.isBlank(content)) { errors.put("content.required","A post of the content bytes " + "is required, either utf-8 or base64 encoded."); } List<String> components=extractForm.getComponents(); boolean hasComponents=(components != null && components.size() > 0); List<String> pipelines=extractForm.getPipelines(); boolean hasPipelines=(pipelines != null && pipelines.size() > 0); if (!hasComponents && !hasPipelines) { errors.put("processors.required","One or more components or pipelines must be specified to process " + "content"); } if (errors.size() > 0) { return errors; } Map output=new HashMap(); byte[] contentBytes=content.getBytes(); if (Base64.isArrayByteBase64(contentBytes)) { try { Base64 base64=new Base64(); contentBytes=base64.decode(contentBytes); contentBytes=StringEscapeUtils.unescapeHtml(new String(contentBytes)).getBytes(); } catch ( Exception e) { Map<String,String> errMap=getErrors(e); errors.put("errors",errMap); return errors; } } if (contentBytes == null || contentBytes.length == 0) { return output; } HashSet<String> componetSet=new HashSet<String>(); componetSet.addAll(components); HashSet<String> pipelineSet=new HashSet<String>(); pipelineSet.addAll(pipelines); return extractContent(contentBytes,pipelineSet,componetSet,extractForm.getConfig(),extractForm.getMetadata()); }
Example 15
From project miso-lims, under directory /core/src/main/java/uk/ac/bbsrc/tgac/miso/core/security/.
Source file: PasswordCodecService.java

/** * Encrypt a plaintext String using a hmac_sha1 salt * @param key of type String * @param plaintext of type String * @return String the encrypted String of the given plaintext String * @throws SignatureException when the HMAC is unable to be generated */ public synchronized String encryptHMACSHA1(String key,String plaintext) throws java.security.SignatureException { String result; try { SecretKeySpec signingKey=new SecretKeySpec(key.getBytes(),"HmacSHA1"); Mac mac=Mac.getInstance("HmacSHA1"); mac.init(signingKey); byte[] rawHmac=mac.doFinal(plaintext.getBytes()); result=new Base64().encodeToString(rawHmac); } catch ( Exception e) { throw new SignatureException("Failed to generate HMAC : " + e.getMessage()); } return result; }
Example 16
From project couchdb-lucene, under directory /src/main/java/com/github/rnewson/couchdb/lucene/couchdb/.
Source file: UpdateSequence.java

private BigCouchUpdateSequence(final String encodedVector,final String packedSeqs){ this.since=encodedVector; final byte[] bytes=new Base64(true).decode(packedSeqs); final OtpInputStream stream=new OtpInputStream(bytes); try { final OtpErlangList list=(OtpErlangList)stream.read_any(); for (int i=0, arity=list.arity(); i < arity; i++) { final OtpErlangTuple tuple=(OtpErlangTuple)list.elementAt(i); final OtpErlangObject node=tuple.elementAt(0); final OtpErlangObject range=tuple.elementAt(1); final OtpErlangLong node_seq=(OtpErlangLong)tuple.elementAt(2); vector.put(node + "-" + range,node_seq.longValue()); } } catch ( final OtpErlangDecodeException e) { throw new IllegalArgumentException(encodedVector + " not valid."); } }
Example 17
From project en4j, under directory /NBPlatformApp/Synchronization/src/main/java/com/rubenlaguna/en4j/sync/.
Source file: EvernoteProtocolUtil.java

private EvernoteProtocolUtil(){ try { KeySpec keySpec=new PBEKeySpec("55xdfsfAxkioou546bnTrjk".toCharArray(),salt,iterationCount); SecretKey key=SecretKeyFactory.getInstance("PBEWithMD5AndDES").generateSecret(keySpec); Cipher dcipher=Cipher.getInstance(key.getAlgorithm()); AlgorithmParameterSpec paramSpec=new PBEParameterSpec(salt,iterationCount); dcipher.init(Cipher.DECRYPT_MODE,key,paramSpec); byte[] dec=new Base64().decode(consumerKey); byte[] utf8=dcipher.doFinal(dec); a=new String(utf8,"UTF8"); dec=new Base64().decode(consumerSecret); utf8=dcipher.doFinal(dec); b=new String(utf8,"UTF8"); } catch ( Exception ex) { Exceptions.printStackTrace(ex); } }
Example 18
From project java_binding_v1, under directory /src/com/tripit/auth/.
Source file: OAuthCredential.java

private String generateSignature(String baseUrl,SortedMap<String,String> args) throws UnsupportedEncodingException, InvalidKeyException, NoSuchAlgorithmException { String encoding="UTF-8"; baseUrl=URLEncoder.encode(baseUrl,encoding); StringBuilder sb=new StringBuilder(); boolean isFirst=true; for ( Map.Entry<String,String> arg : args.entrySet()) { if (isFirst) { isFirst=false; } else { sb.append('&'); } sb.append(URLEncoder.encode(arg.getKey(),encoding)); sb.append('='); sb.append(URLEncoder.encode(arg.getValue(),encoding)); } String parameters=URLEncoder.encode(sb.toString(),encoding); String signatureBaseString="GET&" + baseUrl + "&"+ parameters; String key=(consumerSecret != null ? consumerSecret : "") + "&" + (userSecret != null ? userSecret : ""); String macName="HmacSHA1"; Mac mac=Mac.getInstance(macName); mac.init(new SecretKeySpec(key.getBytes(encoding),macName)); byte[] signature=mac.doFinal(signatureBaseString.getBytes(encoding)); return new Base64().encodeToString(signature).trim(); }
Example 19
From project action-core, under directory /src/main/java/com/ning/metrics/action/endpoint/.
Source file: HdfsBrowser.java

@GET @Produces(MediaType.APPLICATION_JSON) @Path("/viewer") @Timed public Response prettyPrintOneLine(@QueryParam("object") final String object) throws IOException { final ByteArrayOutputStream out=new ByteArrayOutputStream(); final ObjectMapper mapper=new ObjectMapper(); final String objectURIDecoded=URLDecoder.decode(object,"UTF-8"); final byte[] objectBase64Decoded=Base64.decodeBase64(objectURIDecoded.getBytes()); mapper.configure(SerializationFeature.INDENT_OUTPUT,true); final LinkedHashMap map=mapper.readValue(new String(objectBase64Decoded),LinkedHashMap.class); mapper.writeValue(out,map); return Response.ok().entity(new String(out.toByteArray())).build(); }
Example 20
From project airlift, under directory /http-server/src/test/java/io/airlift/http/server/.
Source file: TestHttpServerProvider.java

@Test public void testAuth() throws Exception { File file=File.createTempFile("auth",".properties",tempDir); Files.write("user: password",file,Charsets.UTF_8); config.setUserAuthFile(file.getAbsolutePath()); createServer(); server.start(); HttpClient client=new ApacheHttpClient(); StringResponse response=client.execute(prepareGet().setUri(httpServerInfo.getHttpUri()).addHeader("Authorization","Basic " + Base64.encodeBase64String("user:password".getBytes()).trim()).build(),createStringResponseHandler()); assertEquals(response.getStatusCode(),HttpServletResponse.SC_OK); assertEquals(response.getBody(),"user"); }
Example 21
From project android-share-menu, under directory /src/com/eggie5/.
Source file: post_to_eggie5.java

/** * Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState){ super.onCreate(savedInstanceState); setContentView(R.layout.main); Intent intent=getIntent(); Bundle extras=intent.getExtras(); String action=intent.getAction(); if (Intent.ACTION_SEND.equals(action)) { if (extras.containsKey(Intent.EXTRA_STREAM)) { try { Uri uri=(Uri)extras.getParcelable(Intent.EXTRA_STREAM); ContentResolver cr=getContentResolver(); InputStream is=cr.openInputStream(uri); byte[] data=getBytesFromFile(is); byte[] encoded_data=Base64.encodeBase64(data); String data_string=new String(encoded_data); SendRequest(data_string); return; } catch ( Exception e) { Log.e(this.getClass().getName(),e.toString()); } } else if (extras.containsKey(Intent.EXTRA_TEXT)) { return; } } }
Example 22
From project ANNIS, under directory /annis-service/src/main/java/annis/sqlgen/.
Source file: MatrixSqlGenerator.java

private List<Annotation> extractAnnotations(Array array) throws SQLException { List<Annotation> result=new ArrayList<Annotation>(); if (array != null) { String[] arrayLines=(String[])array.getArray(); for ( String line : arrayLines) { if (line != null) { String namespace=null; String name=null; String value=null; String[] split=line.split(":"); if (split.length > 2) { namespace=split[0]; name=split[1]; value=split[2]; } else if (split.length > 1) { name=split[0]; value=split[1]; } else { name=split[0]; } if (value != null) { try { value=new String(Base64.decodeBase64(value),"UTF-8"); } catch ( UnsupportedEncodingException ex) { log.error(null,ex); } } result.add(new annis.model.Annotation(namespace,name,value)); } } } return result; }
Example 23
From project ardverk-dht, under directory /components/store/src/main/java/org/ardverk/dht/storage/.
Source file: IndexDatastore.java

private static boolean digest(Context context,String name,MessageDigest md){ byte[] actual=md.digest(); String expected=context.getStringValue(name); if (expected != null) { byte[] decoded=Base64.decodeBase64(expected); if (!Arrays.equals(decoded,actual)) { return false; } } else { context.addHeader(name,Base64.encodeBase64String(actual)); } if (name.equals(Constants.CONTENT_MD5)) { String etag="\"" + CodingUtils.encodeBase16(actual) + "\""; context.addHeader(Constants.ETAG,etag); } return true; }
Example 24
From project arquillian-container-tomcat, under directory /tomcat-common/src/main/java/org/jboss/arquillian/container/tomcat/.
Source file: CommonTomcatManager.java

protected String constructHttpBasicAuthHeader(){ String credentials=configuration.getUser() + ":" + configuration.getPass(); try { return "Basic " + Base64.encodeBase64String(credentials.getBytes("ISO-8859-1")); } catch ( UnsupportedEncodingException e) { throw new RuntimeException(e); } }
Example 25
From project arquillian-graphene, under directory /graphene-selenium/graphene-selenium-impl/src/main/java/org/jboss/arquillian/ajocado/framework/.
Source file: TypedSeleniumImpl.java

private BufferedImage decodeBase64Screenshot(String screenshotInBase64){ byte[] screenshotPng=Base64.decodeBase64(screenshotInBase64); ByteArrayInputStream inputStream=new ByteArrayInputStream(screenshotPng); BufferedImage result; try { result=ImageIO.read(inputStream); } catch ( IOException e) { throw new RuntimeException(e); } return result; }
Example 26
From project aws-tvm-anonymous, under directory /src/com/amazonaws/tvm/.
Source file: AESEncryption.java

public static String wrap(String clearText,String key) throws Exception { byte[] iv=getIv(); byte[] cipherText=encrypt(clearText,key,iv); byte[] wrapped=new byte[iv.length + cipherText.length]; System.arraycopy(iv,0,wrapped,0,iv.length); System.arraycopy(cipherText,0,wrapped,16,cipherText.length); return new String(Base64.encodeBase64(wrapped)); }
Example 27
From project aws-tvm-identity, under directory /src/com/amazonaws/tvm/.
Source file: AESEncryption.java

public static String wrap(String clearText,String key) throws Exception { byte[] iv=getIv(); byte[] cipherText=encrypt(clearText,key,iv); byte[] wrapped=new byte[iv.length + cipherText.length]; System.arraycopy(iv,0,wrapped,0,iv.length); System.arraycopy(cipherText,0,wrapped,16,cipherText.length); return new String(Base64.encodeBase64(wrapped)); }
Example 28
/** * To be called by ObjectWriter only. * @throws XMLStreamException */ public void persist(XMLStreamWriter writer) throws XMLStreamException { writer.writeStartElement(XML_TAG_PAGEVERSION); if (m_verProps.numKeys() > 0) { m_verProps.persist(writer); } if (m_parseMeta.numKeys() > 0) { m_parseMeta.persist(writer); } if (m_contentMeta.numKeys() > 0) { m_contentMeta.persist(writer); } if (m_outLinks != null) { String anchor; writer.writeStartElement(XML_TAG_OUT_LINKS); for ( Outlink outlink : m_outLinks) { writer.writeStartElement(XML_TAG_LINK); anchor=outlink.getAnchor(); if ((anchor != null) && (anchor.length() != 0)) { writer.writeAttribute(XML_ATTRIB_ANCHOR,anchor); } writer.writeCharacters(outlink.getToUrl()); writer.writeEndElement(); } writer.writeEndElement(); } if (m_content.length() > 0) { writer.writeStartElement(XML_TAG_CONTENT); writer.writeCharacters(new String(Base64.encodeBase64(m_content.getBytes()))); writer.writeEndElement(); } writer.writeEndElement(); }
Example 29
From project backend-update-center2, under directory /src/main/java/org/jvnet/hudson/update_center/.
Source file: MavenArtifact.java

/** * Computes the SHA1 signature of the file. */ public String getDigest() throws IOException { try { MessageDigest sig=MessageDigest.getInstance("SHA1"); FileInputStream fin=new FileInputStream(resolve()); byte[] buf=new byte[2048]; int len; while ((len=fin.read(buf,0,buf.length)) >= 0) sig.update(buf,0,len); return new String(Base64.encodeBase64(sig.digest())); } catch ( NoSuchAlgorithmException e) { throw new IOException(e); } }
Example 30
From project BHT-FPA, under directory /mailer-common/de.bht.fpa.mail.common/src/de/bht/fpa/mail/s000000/common/mail/imapsync/.
Source file: MessageConverter.java

private static void handleInputStream(InputStream content,BodyPart bodyPart,MessageBuilder messageBuilder){ ByteArrayOutputStream bos=new ByteArrayOutputStream(); try { int thisLine; while ((thisLine=content.read()) != -1) { bos.write(thisLine); } bos.flush(); byte[] bytes=bos.toByteArray(); bos.close(); String encodeBase64String=new String(Base64.encodeBase64(bytes)); messageBuilder.attachment(newAttachmentBuilder().fileName(bodyPart.getFileName()).body(encodeBase64String)); } catch ( Exception e) { return; } }
Example 31
From project BioMAV, under directory /Behavior/src/nl/ru/ai/projects/parrot/tools/.
Source file: TwitterAccess.java

/** * Uploads an image * @param image The image to upload * @param tweet The text of the tweet that needs to be posted with the image */ public void uploadImage(byte[] image,String tweet){ if (!enabled) return; ByteArrayOutputStream baos=new ByteArrayOutputStream(); RenderedImage img=getImageFromCamera(image); try { ImageIO.write(img,"jpg",baos); URL url=new URL("http://api.imgur.com/2/upload.json"); String data=URLEncoder.encode("image","UTF-8") + "=" + URLEncoder.encode(Base64.encodeBase64String(baos.toByteArray()),"UTF-8"); data+="&" + URLEncoder.encode("key","UTF-8") + "="+ URLEncoder.encode("f9c4861fc0aec595e4a64dd185751d28","UTF-8"); URLConnection conn=url.openConnection(); conn.setDoOutput(true); OutputStreamWriter wr=new OutputStreamWriter(conn.getOutputStream()); wr.write(data); wr.flush(); StringBuffer buffer=new StringBuffer(); InputStreamReader isr=new InputStreamReader(conn.getInputStream()); Reader in=new BufferedReader(isr); int ch; while ((ch=in.read()) > -1) buffer.append((char)ch); String imgURL=processJSON(buffer.toString()); setStatus(tweet + " " + imgURL,100); } catch ( IOException e1) { e1.printStackTrace(); } }
Example 32
From project bpelunit, under directory /net.bpelunit.framework/src/main/java/net/bpelunit/framework/control/deploy/activebpel/.
Source file: BPRDeployRequestEntity.java

@Override protected void populateMessage(SOAPMessage message) throws SOAPException, IOException { SOAPElement xmlDeployBpr=addRootElement(message,new QName(ACTIVEBPEL_ELEMENT_DEPLOYBPR)); SOAPElement xmlBprFilename=xmlDeployBpr.addChildElement(ACTIVEBPEL_ELEMENT_ABPRFILENAME); xmlBprFilename.addAttribute(new QName(ActiveBPELRequestEntityBase.NS_XMLSCHEMA_INSTANCE,"type"),XSD_STRING); xmlBprFilename.setTextContent(FilenameUtils.getName(file.toString())); SOAPElement xmlBase64File=xmlDeployBpr.addChildElement(ACTIVEBPEL_ELEMENT_ABASE64FILE); xmlBase64File.addAttribute(new QName(ActiveBPELRequestEntityBase.NS_XMLSCHEMA_INSTANCE,"type"),XSD_STRING); StringBuilder content=new StringBuilder(); byte[] arr=FileUtils.readFileToByteArray(file); byte[] encoded=Base64.encodeBase64Chunked(arr); for (int i=0; i < encoded.length; i++) { content.append((char)encoded[i]); } xmlBase64File.setTextContent(content.toString()); }
Example 33
From project cascading, under directory /src/hadoop/cascading/flow/hadoop/util/.
Source file: HadoopUtil.java

public static String encodeBytes(byte[] bytes){ try { return new String(Base64.encodeBase64(bytes),ENCODING); } catch ( UnsupportedEncodingException exception) { throw new RuntimeException(exception); } }
Example 34
From project cloudbees-api-client, under directory /cloudbees-api-client/src/main/java/com/cloudbees/api/.
Source file: BeesClient.java

/** * Common initialization code in this class. */ private void init(){ BeesClientConfiguration conf=getBeesClientConfiguration(); try { base=new URL(conf.getServerApiUrl()); } catch ( MalformedURLException e) { throw new IllegalArgumentException("Invalid API URL:" + conf.getServerApiUrl(),e); } if (conf.getApiKey() != null || conf.getSecret() != null) { String userpassword=conf.getApiKey() + ':' + conf.getSecret(); encodedAccountAuthorization=new String(Base64.encodeBase64(userpassword.getBytes())); } else encodedAccountAuthorization=null; }
Example 35
From project clutter, under directory /src/clutter/hypertoolkit/security/.
Source file: Hash.java

public SaltedSum(String salt,String input){ try { StringBuilder sb=new StringBuilder(); sb.append(salt); sb.append(StringUtils.defaultString(input)); MessageDigest digest=MessageDigest.getInstance("SHA1"); digest.update(sb.toString().getBytes("UTF-8")); byte[] hash=digest.digest(); StringBuilder output=new StringBuilder(); output.append(salt); output.append(new String(Base64.encodeBase64(hash))); result=output.toString(); } catch ( Exception e) { Log.fatal(this,"WTF - This JVM cannot do SHA1 or UTF8 or base64???",e); throw new RuntimeException(e); } }
Example 36
From project CMM-data-grabber, under directory /benny/src/main/java/au/edu/uq/cmm/benny/.
Source file: Benny.java

private String[] getBasicAuthCredentials(HttpServletRequest req){ String authorization=req.getHeader("Authorization"); if (authorization == null) { return null; } Matcher matcher=BASIC_AUTH_PATTERN.matcher(authorization); if (matcher.matches()) { String base64=matcher.group(1); String userPass=new String(Base64.decodeBase64(base64),UTF_8); int colonPos=userPass.indexOf(":"); if (colonPos <= 0 || colonPos == userPass.length() - 1) { return null; } else { return new String[]{userPass.substring(0,colonPos),userPass.substring(colonPos + 1)}; } } else { return null; } }
Example 37
From project cmsandroid, under directory /src/com/zia/freshdocs/preference/.
Source file: CMISPreferencesManager.java

@SuppressWarnings("unchecked") protected Map<String,CMISHost> readPreferences(Context ctx){ ConcurrentHashMap<String,CMISHost> prefs=new ConcurrentHashMap<String,CMISHost>(); SharedPreferences sharedPrefs=PreferenceManager.getDefaultSharedPreferences(ctx); String encPrefs=null; if (sharedPrefs.contains(SERVERS_KEY)) { encPrefs=sharedPrefs.getString(SERVERS_KEY,null); if (encPrefs != null) { byte[] repr=Base64.decodeBase64(encPrefs.getBytes()); Object obj=SerializationUtils.deserialize(repr); if (obj != null) { prefs=(ConcurrentHashMap<String,CMISHost>)obj; } } } return prefs; }
Example 38
From project cogroo4, under directory /lang/pt_br/cogroo-addon/src/org/cogroo/addon/util/.
Source file: SecurityUtil.java

public byte[] decodeURLSafe(String encoded){ byte[] bytes=null; try { bytes=Base64.decodeBase64(URLDecoder.decode(encoded,UTF8).getBytes(UTF8)); } catch ( Exception e) { LOG.log(Level.SEVERE,"Error decoding string: " + encoded,e); } return bytes; }
Example 39
From project crunch, under directory /crunch/src/main/java/org/apache/crunch/io/impl/.
Source file: InputBundle.java

public static InputBundle fromSerialized(String serialized){ ByteArrayInputStream bais=new ByteArrayInputStream(Base64.decodeBase64(serialized)); try { ObjectInputStream ois=new ObjectInputStream(bais); InputBundle bundle=(InputBundle)ois.readObject(); ois.close(); return bundle; } catch ( IOException e) { throw new RuntimeException(e); } catch ( ClassNotFoundException e) { throw new RuntimeException(e); } }
Example 40
From project culvert, under directory /culvert-main/src/main/java/com/bah/culvert/data/index/.
Source file: Index.java

/** * Used to set a key indicating if the string value held by another configuration key is a base64 encoded binary or not. * @param isValueBinaryEncodedSetting The key telling weather or not the otherkey (setting) is base64. * @param potentiallyEncodedSetting The actual key that might be base64encoded. * @param data The data to set as base64. * @param conf The configuration to do the setting on. */ private static void setBinaryConfSetting(String isValueBinaryEncodedSetting,String potentiallyEncodedSetting,byte[] data,Configuration conf){ CharsetDecoder decoder=UTF_8.newDecoder(); decoder.onMalformedInput(CodingErrorAction.REPORT); try { CharBuffer colFamString=decoder.decode(ByteBuffer.wrap(data)); conf.setBoolean(isValueBinaryEncodedSetting,false); conf.set(potentiallyEncodedSetting,colFamString.toString()); } catch ( CharacterCodingException e) { conf.setBoolean(isValueBinaryEncodedSetting,true); conf.set(potentiallyEncodedSetting,new String(Base64.encodeBase64(data),UTF_8)); } }
Example 41
From project dragon, under directory /hadoop-dragon-core/src/main/java/org/apache/hadoop/realtime/server/.
Source file: DragonClientService.java

public void start(){ Configuration conf=getConfig(); YarnRPC rpc=YarnRPC.create(conf); InetSocketAddress address=NetUtils.createSocketAddr("0.0.0.0:0"); InetAddress hostNameResolved=null; try { hostNameResolved=InetAddress.getLocalHost(); } catch ( UnknownHostException e) { throw new YarnException(e); } ClientToAMSecretManager secretManager=null; if (UserGroupInformation.isSecurityEnabled()) { secretManager=new ClientToAMSecretManager(); String secretKeyStr=System.getenv(ApplicationConstants.APPLICATION_CLIENT_SECRET_ENV_NAME); byte[] bytes=Base64.decodeBase64(secretKeyStr); ClientTokenIdentifier identifier=new ClientTokenIdentifier(this.appContext.getApplicationID()); secretManager.setMasterKey(identifier,bytes); } server=rpc.getServer(DragonClientProtocol.class,protocolHandler,address,conf,secretManager,conf.getInt(DragonJobConfig.DRAGON_AM_JOB_CLIENT_THREAD_COUNT,DragonJobConfig.DEFAULT_DRAGON_AM_JOB_CLIENT_THREAD_COUNT)); if (conf.getBoolean(CommonConfigurationKeysPublic.HADOOP_SECURITY_AUTHORIZATION,false)) { refreshServiceAcls(conf,new DragonAMPolicyProvider()); } server.start(); this.bindAddress=NetUtils.createSocketAddr(hostNameResolved.getHostAddress() + ":" + server.getPort()); LOG.info("Instantiated DRAGONClientService at " + this.bindAddress); try { webApp=WebApps.$for("dragon",AppContext.class,appContext,"ws").with(conf).start(new DragonWebApp()); } catch ( Exception e) { LOG.error("Webapps failed to start. Ignoring for now:",e); } super.start(); }
Example 42
From project ecoadapters, under directory /ecoadapters/src/main/java/com/inadco/ecoadapters/pig/.
Source file: PigUtil.java

static public String stringifySchema(Schema pigSchema) throws IOException { ByteArrayOutputStream baos=new ByteArrayOutputStream(); ObjectOutputStream oos=new ObjectOutputStream(baos); try { oos.writeObject(pigSchema); } finally { oos.close(); } return new String(Base64.encodeBase64(baos.toByteArray()),"ASCII"); }
Example 43
From project entando-core-engine, under directory /src/main/java/com/agiletec/aps/util/.
Source file: DefaultApsEncrypter.java

public static String decrypt(String source){ try { Key key=getKey(); Cipher desCipher=Cipher.getInstance(TRIPLE_DES); byte[] dec=Base64.decodeBase64(source.getBytes()); desCipher.init(Cipher.DECRYPT_MODE,key); byte[] cleartext=desCipher.doFinal(dec); return new String(cleartext); } catch ( Throwable t) { throw new RuntimeException("Error decrypting string",t); } }
Example 44
From project event-collector, under directory /event-combiner/src/main/java/com/proofpoint/event/combiner/.
Source file: S3CombineObjectMetadataStore.java

private boolean writeMetadataFile(EventPartition eventPartition,CombinedGroup combinedGroup,String sizeName){ byte[] json=jsonCodec.toJson(combinedGroup).getBytes(Charsets.UTF_8); URI metadataFile=toMetadataLocation(eventPartition,sizeName); try { ObjectMetadata metadata=new ObjectMetadata(); metadata.setContentLength(json.length); metadata.setContentMD5(Base64.encodeBase64String(DigestUtils.md5(json))); metadata.setContentType(MediaType.APPLICATION_JSON); InputStream input=new ByteArrayInputStream(json); s3Service.putObject(getS3Bucket(metadataFile),getS3ObjectKey(metadataFile),input,metadata); return true; } catch ( AmazonClientException e) { log.warn(e,"error writing metadata file: %s",metadataFile); return false; } }
Example 45
From project examples_5, under directory /twittertopiccount/src/main/java/io/s4/example/twittertopiccount/.
Source file: TwitterFeedListener.java

public void connectAndRead() throws Exception { URL url=new URL(urlString); URLConnection connection=url.openConnection(); String userPassword=userid + ":" + password; String encoded=EncodingUtil.getAsciiString(Base64.encodeBase64(EncodingUtil.getAsciiBytes(userPassword))); connection.setRequestProperty("Authorization","Basic " + encoded); connection.connect(); InputStream is=connection.getInputStream(); InputStreamReader isr=new InputStreamReader(is); BufferedReader br=new BufferedReader(isr); String inputLine=null; while ((inputLine=br.readLine()) != null) { if (inputLine.trim().length() == 0) { blankCount++; continue; } messageCount++; messageQueue.add(inputLine); } }
Example 46
From project figgo, under directory /src/main/java/br/octahedron/figgo/modules/admin/util/.
Source file: Route53Util.java

protected static String sign(String content,String key) throws InvalidKeySpecException, NoSuchAlgorithmException, InvalidKeyException, IllegalStateException { Mac mac=Mac.getInstance(MAC_ALGORITHM); SecretKey skey=new SecretKeySpec(key.getBytes(),KEY_ALGORITHM); mac.init(skey); mac.update(content.getBytes()); return new String(Base64.encodeBase64((mac.doFinal()))); }
Example 47
From project flume_1, under directory /flume-core/src/main/java/com/cloudera/flume/core/.
Source file: DigestDecorator.java

@Override public synchronized void append(Event e) throws IOException, InterruptedException { this.stomach.reset(); this.stomach.update(e.getBody()); byte digest[]=this.stomach.digest(); if (this.encodeBase64) { digest=Base64.encodeBase64(digest); } e.set(this.attr,digest); super.append(e); }
Example 48
From project frascati-studio-social, under directory /src/org/apache/commons/codec/net/.
Source file: BCodec.java

@Override protected byte[] doEncoding(byte[] bytes){ if (bytes == null) { return null; } return Base64.encodeBase64(bytes); }
Example 49
From project gibson, under directory /gibson-core/src/main/java/org/ardverk/gibson/.
Source file: EventUtils.java

public static String signature(Event event){ if (event == null) { throw new NullPointerException("event"); } MessageDigest md=createMessageDigest(ALGORITHM); append(md,event.getLogger()); append(md,event.getMarker()); append(md,event.getLevel()); append(md,event.getCondition()); return Base64.encodeBase64URLSafeString(md.digest()); }
Example 50
From project glimpse, under directory /glimpse-client/src/main/java/br/com/tecsinapse/glimpse/client/http/.
Source file: HttpInvoker.java

public String invoke(String context,String body){ try { HttpClient client=new HttpClient(); PostMethod post=new PostMethod(url + context); String base64=username + ":" + password; post.setRequestHeader("Authorization","Basic " + new String(Base64.encodeBase64(base64.getBytes()))); post.setRequestEntity(new StringRequestEntity(body,"text/plain","UTF-8")); int statusCode=client.executeMethod(post); StringBuilder builder=new StringBuilder(); InputStream in=post.getResponseBodyAsStream(); if (in != null) { int c=0; while ((c=in.read()) != -1) { builder.append((char)c); } } post.releaseConnection(); if (statusCode == HttpStatus.SC_OK) { return builder.toString(); } else if (statusCode == HttpStatus.SC_UNAUTHORIZED) { return "update\nStatus: " + statusCode + "\nUnauthorized Access, check your username and password.\nclose\n"; } else { return "update\nStatus: " + statusCode + "\n"+ builder.toString()+ "\nclose\n"; } } catch ( UnsupportedEncodingException e) { return exceptionResult(e); } catch ( HttpException e) { return exceptionResult(e); } catch ( IOException e) { return exceptionResult(e); } }
Example 51
From project guj.com.br, under directory /src/net/jforum/view/forum/.
Source file: UserAction.java

private boolean parseBasicAuthentication(){ if (hasBasicAuthentication(request)) { String auth=request.getHeader("Authorization"); String decoded; try { decoded=new String(new Base64().decode(auth.substring(6)).toString()); } catch ( Exception e) { throw new ForumException(e); } int p=decoded.indexOf(':'); if (p != -1) { request.setAttribute("username",decoded.substring(0,p)); request.setAttribute("password",decoded.substring(p + 1)); return true; } } return false; }
Example 52
From project gwtphonegap, under directory /src/main/java/com/googlecode/gwtphonegap/server/file/.
Source file: FileRemoteServiceServlet.java

@Override public String readAsDataUrl(String relativePath) throws FileErrorException { File basePath=new File(path); File file=new File(basePath,relativePath); ensureLocalRoot(basePath,file); try { byte[] binaryData=FileUtils.readFileToByteArray(file); byte[] base64=Base64.encodeBase64(binaryData); String base64String=new String(base64,"UTF-8"); String mimeType=guessMimeType(file); return "data:" + mimeType + ";base64,"+ base64String; } catch ( IOException e) { logger.log(Level.WARNING,"error while reading file",e); throw new FileErrorException(FileError.NOT_READABLE_ERR); } }
Example 53
From project ha-jdbc, under directory /src/main/java/net/sf/hajdbc/codec/crypto/.
Source file: CipherCodec.java

/** * {@inheritDoc} * @see net.sf.hajdbc.codec.Codec#decode(java.lang.String) */ @Override public String decode(String value) throws SQLException { try { Cipher cipher=Cipher.getInstance(this.key.getAlgorithm()); cipher.init(Cipher.DECRYPT_MODE,this.key); return new String(cipher.doFinal(Base64.decodeBase64(value.getBytes()))); } catch ( GeneralSecurityException e) { throw new SQLException(e); } }
Example 54
From project hank, under directory /src/java/com/rapleaf/hank/hadoop/.
Source file: DomainBuilderProperties.java

public static CoordinatorConfigurator getConfigurator(JobConf conf){ String domainName=getDomainName(conf); String configurationItem=DomainBuilderAbstractOutputFormat.createConfParamName(domainName,DomainBuilderAbstractOutputFormat.CONF_PARAM_HANK_CONFIGURATOR); String configuratorString=getRequiredConfigurationItem(configurationItem,"Hank coordinator configuration",conf); CoordinatorConfigurator configurator; try { configurator=(CoordinatorConfigurator)new ObjectInputStream(new ByteArrayInputStream(Base64.decodeBase64(configuratorString.getBytes()))).readObject(); } catch ( Exception e) { throw new RuntimeException("Hank Configurator is incorrectly serialized in configuration item: " + configurationItem,e); } return configurator; }
Example 55
From project HBase-Lattice, under directory /hbl/src/main/java/com/inadco/hbl/compiler/.
Source file: YamlModelParser.java

public static Cube decodeCubeModel(String encoded) throws IOException { ByteArrayOutputStream baos=new ByteArrayOutputStream(); OutputStream os=new InflaterOutputStream(baos,new Inflater(false)); os.write(Base64.decodeBase64(encoded.getBytes("US-ASCII"))); os.close(); return parseYamlModel(new String(baos.toByteArray(),"utf-8")); }
Example 56
From project heritrix3, under directory /modules/src/main/java/org/archive/modules/recrawl/.
Source file: PersistProcessor.java

/** * Populates an environment db from a persist log. If historyMap is not provided, only logs the entries that would have been populated. * @param persistLogReader persist log * @param historyMap new environment db (or null for a dry run) * @return number of records * @throws UnsupportedEncodingException * @throws DatabaseException */ private static int populatePersistEnvFromLog(BufferedReader persistLogReader,StoredSortedMap<String,Map> historyMap) throws UnsupportedEncodingException, DatabaseException { int count=0; Iterator<String> iter=new LineReadingIterator(persistLogReader); while (iter.hasNext()) { String line=iter.next(); if (line.length() == 0) { continue; } String[] splits=line.split(" "); if (splits.length != 2) { logger.severe("bad line has " + splits.length + " fields (should be 2): "+ line); continue; } Map alist; try { alist=(Map)SerializationUtils.deserialize(Base64.decodeBase64(splits[1].getBytes("UTF-8"))); } catch ( Exception e) { logger.severe("caught exception " + e + " deserializing line: "+ line); continue; } if (logger.isLoggable(Level.FINE)) { logger.fine(splits[0] + " " + ArchiveUtils.prettyString(alist)); } if (historyMap != null) try { historyMap.put(splits[0],alist); } catch ( Exception e) { logger.log(Level.SEVERE,"caught exception after loading " + count + " urls from the persist log (perhaps crawl was stopped by user?)",e); IOUtils.closeQuietly(persistLogReader); return count; } count++; } IOUtils.closeQuietly(persistLogReader); return count; }
Example 57
public String send(java.util.Map value){ String p=(String)value.get("packet"); byte[] b=Base64.decodeBase64(p.getBytes()); Packet packet=new Packet(b); try { ((PortXmlrpc)app.homenet.getPort("xmlrpc")).receive(packet); } catch ( Exception e) { e.printStackTrace(); } return "true"; }
Example 58
From project incubator-cordova-android, under directory /framework/src/org/apache/cordova/.
Source file: CameraLauncher.java

/** * Compress bitmap using jpeg, convert to Base64 encoded string, and return to JavaScript. * @param bitmap */ public void processPicture(Bitmap bitmap){ ByteArrayOutputStream jpeg_data=new ByteArrayOutputStream(); try { if (bitmap.compress(CompressFormat.JPEG,mQuality,jpeg_data)) { byte[] code=jpeg_data.toByteArray(); byte[] output=Base64.encodeBase64(code); String js_out=new String(output); this.callbackContext.success(js_out); js_out=null; output=null; code=null; } } catch ( Exception e) { this.failPicture("Error compressing image."); } jpeg_data=null; }
Example 59
From project incubator-s4, under directory /subprojects/s4-core/src/test/java/org/apache/s4/core/ft/.
Source file: CheckpointingTest.java

@Test public void testCheckpointStorage() throws Exception { final ZooKeeper zk=CoreTestUtils.createZkClient(); final CountDownLatch signalValue1Set=new CountDownLatch(1); CoreTestUtils.watchAndSignalCreation("/value1Set",signalValue1Set,zk); final CountDownLatch signalCheckpointed=new CountDownLatch(1); CoreTestUtils.watchAndSignalCreation("/checkpointed",signalCheckpointed,zk); Injector injector=Guice.createInjector(new MockCommModule(),new MockCoreModuleWithFileBaseCheckpointingBackend()); TestApp app=injector.getInstance(TestApp.class); app.init(); app.start(); Event event=new Event(); event.put("command",String.class,"setValue1"); event.put("value",String.class,"message1"); app.testStream.receiveEvent(new EventMessage("","stream1",app.getSerDeser().serialize(event))); signalValue1Set.await(); StatefulTestPE pe=(StatefulTestPE)app.getPE("statefulPE1").getInstanceForKey("X"); Assert.assertEquals("message1",pe.getValue1()); Assert.assertEquals("",pe.getValue2()); event=new Event(); event.put("command",String.class,"checkpoint"); app.testStream.receiveEvent(new EventMessage("","stream1",app.getSerDeser().serialize(event))); Assert.assertTrue(signalCheckpointed.await(10,TimeUnit.SECONDS)); Thread.sleep(1000); CheckpointId safeKeeperId=new CheckpointId(pe); File expected=new File(System.getProperty("user.dir") + File.separator + "tmp"+ File.separator+ "storage"+ File.separator+ safeKeeperId.getPrototypeId()+ File.separator+ Base64.encodeBase64URLSafeString(safeKeeperId.getStringRepresentation().getBytes())); Assert.assertTrue(expected.exists()); StatefulTestPE refPE=new StatefulTestPE(); refPE.onCreate(); refPE.setValue1("message1"); Field idField=ProcessingElement.class.getDeclaredField("id"); idField.setAccessible(true); idField.set(refPE,"X"); byte[] refBytes=app.getSerDeser().serialize(refPE); Assert.assertTrue(Arrays.equals(refBytes,Files.toByteArray(expected))); }
Example 60
From project ios-driver, under directory /client/src/main/java/org/uiautomation/ios/client/uiamodels/impl/.
Source file: RemoteUIATarget.java

public static void createFileFrom64EncodedString(File f,String encoded64) throws IOException { byte[] img64=Base64.decodeBase64(encoded64); FileOutputStream os=new FileOutputStream(f); os.write(img64); os.close(); }
Example 61
From project james-imap, under directory /processor/src/main/java/org/apache/james/imap/processor/.
Source file: AuthenticateProcessor.java

/** * Parse the initialClientResponse and do a PLAIN AUTH with it * @param initialClientResponse * @param session * @param tag * @param command * @param responder */ protected void doPlainAuth(String initialClientResponse,ImapSession session,String tag,ImapCommand command,Responder responder){ String pass=null; String user=null; try { String userpass=new String(Base64.decodeBase64(initialClientResponse)); StringTokenizer authTokenizer=new StringTokenizer(userpass,"\0"); String authorize_id=authTokenizer.nextToken(); user=authTokenizer.nextToken(); try { pass=authTokenizer.nextToken(); } catch ( java.util.NoSuchElementException _) { pass=user; user=authorize_id; } authTokenizer=null; } catch ( Exception e) { } doAuth(user,pass,session,tag,command,responder,HumanReadableText.AUTHENTICATION_FAILED); }
Example 62
From project jAPS2, under directory /src/com/agiletec/aps/util/.
Source file: DefaultApsEncrypter.java

public static String decrypt(String source){ try { Key key=getKey(); Cipher desCipher=Cipher.getInstance(TRIPLE_DES); byte[] dec=Base64.decodeBase64(source.getBytes()); desCipher.init(Cipher.DECRYPT_MODE,key); byte[] cleartext=desCipher.doFinal(dec); return new String(cleartext); } catch ( Throwable t) { throw new RuntimeException("Error decrypting string",t); } }
Example 63
From project jBilling, under directory /src/java/com/sapienter/jbilling/common/.
Source file: JBCrypto.java

public String digest(String input){ MessageDigest md5; try { md5=MessageDigest.getInstance("MD5"); } catch ( NoSuchAlgorithmException e) { throw new IllegalStateException("MD5 digest is expected to be available :" + e); } byte[] hash=md5.digest(input.getBytes(UTF8)); return useHexForBinary ? com.sapienter.jbilling.server.util.Util.binaryToString(hash) : new String(Base64.encodeBase64(hash)); }
Example 64
From project jena-fuseki, under directory /src/main/java/org/apache/jena/fuseki/mgt/.
Source file: ActionDataset.java

/** * This method returns true if the HttpServletRequest contains a valid authorisation header * @param req The HttpServletRequest to test * @return true if the Authorisation header is valid */ private boolean authenticate(HttpServletRequest req){ String authhead=req.getHeader("Authorization"); if (authhead != null) { byte[] up=Base64.decodeBase64(authhead.substring(6)); String usernpass; try { usernpass=new String(up,"ascii"); } catch ( UnsupportedEncodingException e) { e.printStackTrace(); usernpass=null; } String user=usernpass.substring(0,usernpass.indexOf(":")); String password=usernpass.substring(usernpass.indexOf(":") + 1); if (user.equals("user") && password.equals("pass")) return true; } return false; }
Example 65
From project jira-hudson-integration, under directory /jira-hudson-plugin/src/main/java/com/marvelution/jira/plugins/hudson/encryption/.
Source file: StringEncrypter.java

/** * Encrypt a given {@link String} * @param stringToEncrypt the {@link String} to encrypt * @return the encrypted {@link String} */ public String encrypt(String stringToEncrypt){ if (stringToEncrypt == null || stringToEncrypt.length() == 0) { return ""; } try { initiliseCipher(Cipher.ENCRYPT_MODE); return new String(Base64.encodeBase64(cipher.doFinal(stringToEncrypt.getBytes(UNICODE_FORMAT)))); } catch ( Exception e) { LOGGER.error("Failed to encrypt provided String. Reason: " + e.getMessage(),e); throw new StringEncryptionException("Failed to encrypt provided String. Reason: " + e.getMessage(),e); } }
Example 66
/** * <p> Helper method that creates an RFC 2307-compliant salted, hashed password with the SHA1 MessageDigest algorithm. After the password is digested, the first 20 bytes of the digest will be the actual password hash; the remaining bytes will be the salt. Thus, supplying a password <code>testing123</code> and a random salt <code>foo</code> produces the hash: </p> <blockquote><code>{SSHA}yfT8SRT/WoOuNuA6KbJeF10OznZmb28=</code></blockquote> <p> In layman's terms, the formula is <code>digest( secret + salt ) + salt</code>. The resulting digest is Base64-encoded.</p> * @param password the password to be digested * @param salt the random salt * @return the Base64-encoded password hash, prepended by <code>{SSHA}</code>. * @throws NoSuchAlgorithmException If your JVM is totally b0rked and does not have SHA1. */ protected static String getSaltedPassword(byte[] password,byte[] salt) throws NoSuchAlgorithmException { MessageDigest digest=MessageDigest.getInstance("SHA"); digest.update(password); byte[] hash=digest.digest(salt); byte[] all=new byte[hash.length + salt.length]; for (int i=0; i < hash.length; i++) { all[i]=hash[i]; } for (int i=0; i < salt.length; i++) { all[hash.length + i]=salt[i]; } byte[] base64=Base64.encodeBase64(all); String saltedString=null; try { saltedString=SSHA + new String(base64,"UTF8"); } catch ( UnsupportedEncodingException e) { log.fatal("You do not have UTF-8!?!"); } return saltedString; }
Example 67
From project Kairos, under directory /src/plugin/protocol-httpclient/src/java/org/apache/nutch/protocol/httpclient/.
Source file: HttpBasicAuthentication.java

/** * Construct an HttpBasicAuthentication for the given challenge parameters. The challenge parameters are returned by the web server using a WWW-Authenticate header. This will typically be represented by single line of the form <code>WWW-Authenticate: Basic realm="myrealm"</code> * @param challenge WWW-Authenticate header from web server */ protected HttpBasicAuthentication(String challenge,Configuration conf) throws HttpAuthenticationException { setConf(conf); this.challenge=challenge; credentials=new ArrayList(); String username=this.conf.get("http.auth.basic." + challenge + ".user"); String password=this.conf.get("http.auth.basic." + challenge + ".password"); if (LOG.isTraceEnabled()) { LOG.trace("BasicAuthentication challenge is " + challenge); LOG.trace("BasicAuthentication username=" + username); LOG.trace("BasicAuthentication password=" + password); } if (username == null) { throw new HttpAuthenticationException("Username for " + challenge + " is null"); } if (password == null) { throw new HttpAuthenticationException("Password for " + challenge + " is null"); } byte[] credBytes=(username + ":" + password).getBytes(); credentials.add("Authorization: Basic " + new String(Base64.encodeBase64(credBytes))); if (LOG.isTraceEnabled()) { LOG.trace("Basic credentials: " + credentials); } }
Example 68
From project Karotz-Plugin, under directory /src/main/java/org/jenkinsci/plugins/karotz/.
Source file: KarotzUtil.java

/** * Creates HmacSha1. * @param secretKey SecretKey * @param data target data * @return HmacSha1 * @throws KarotzException Illegal encoding. */ public static String doHmacSha1(String secretKey,String data) throws KarotzException { String hmacSha1; try { Mac mac=Mac.getInstance("HmacSHA1"); SecretKeySpec secret=new SecretKeySpec(secretKey.getBytes("ASCII"),"HmacSHA1"); mac.init(secret); byte[] digest=mac.doFinal(data.getBytes("UTF-8")); hmacSha1=new String(Base64.encodeBase64(digest),"ASCII"); } catch ( IllegalStateException e) { throw new KarotzException(e); } catch ( InvalidKeyException e) { throw new KarotzException(e); } catch ( NoSuchAlgorithmException e) { throw new KarotzException(e); } catch ( UnsupportedEncodingException e) { throw new KarotzException(e); } return hmacSha1; }
Example 69
From project kitten, under directory /java/common/src/main/java/com/cloudera/kitten/util/.
Source file: LocalDataHelper.java

public static <T>String serialize(Map<String,T> mapping){ ByteArrayOutputStream baos=new ByteArrayOutputStream(); try { ObjectOutputStream oos=new ObjectOutputStream(baos); oos.writeObject(mapping); oos.close(); } catch ( IOException e) { throw new RuntimeException(e); } return Base64.encodeBase64String(baos.toByteArray()); }
Example 70
From project lenya, under directory /org.apache.lenya.core.ac/src/main/java/org/apache/lenya/ac/impl/.
Source file: UserAuthenticator.java

public boolean authenticate(AccreditableManager accreditableManager,HttpServletRequest request) throws AccessControlException { String username=null; String password=null; boolean useHeader=false; if (request.getHeader("Authorization") != null) { String encoded=request.getHeader("Authorization"); if (encoded.indexOf("Basic") > -1) { encoded=encoded.trim(); encoded=encoded.substring(encoded.indexOf(' ') + 1); String unencoded=new String(Base64.decodeBase64(encoded.getBytes())); if (unencoded.indexOf(":") - 1 > -1) { useHeader=true; username=unencoded.substring(0,unencoded.indexOf(":")); password=unencoded.substring(unencoded.indexOf(":") + 1); } } } if (!useHeader && request.getParameter("username") != null) { username=request.getParameter("username").toLowerCase(); password=request.getParameter("password"); } if (getLogger().isDebugEnabled()) { getLogger().debug("Authenticating username [" + username + "] with password ["+ password+ "]"); } if (username == null || password == null) { throw new AccessControlException("Username or password is null!"); } Identity identity=(Identity)request.getSession(false).getAttribute(Identity.class.getName()); if (identity == null) { throw new AccessControlException("The session does not contain the identity!"); } boolean authenticated=authenticate(accreditableManager,username,password,identity); return authenticated; }
Example 71
From project lesscss-servlet, under directory /src/main/java/com/asual/lesscss/.
Source file: ResourcePackage.java

public String toString(){ try { if (extension != null && !extensions.contains(extension)) { throw new Exception("Unsupported extension: " + extension); } int mask=0; if (name != null) { mask=mask | NAME_FLAG; } if (version != null) { mask=mask | VERSION_FLAG; } String key=mask + NEW_LINE + StringUtils.join(resources,NEW_LINE); if (!cache.containsKey(key)) { byte[] bytes=key.getBytes(ENCODING); StringBuilder sb=new StringBuilder(); sb.append("/"); sb.append(name == null ? "" : name + SEPARATOR); sb.append(version == null ? "" : version + SEPARATOR); sb.append(Base64.encodeBase64URLSafeString(bytes.length < DEFLATE ? bytes : deflate(bytes)).replaceAll("-","+")); sb.append(extension == null ? "" : "." + extension); cache.put(key,sb.toString()); } return cache.get(key); } catch ( Exception e) { logger.error(e.getMessage(),e); } return null; }
Example 72
From project LightCouch, under directory /src/test/java/org/lightcouch/tests/.
Source file: CouchDbClientTest.java

@Test public void testSaveAttachmentInline(){ System.out.println("------------------------------- Testing Save Attachment - Inline"); Attachment attachment1=new Attachment(); attachment1.setContentType("text/plain"); attachment1.setData("VGhpcyBpcyBhIGJhc2U2NCBlbmNvZGVkIHRleHQ="); Attachment attachment2=new Attachment(); attachment2.setContentType("text/plain"); String data=Base64.encodeBase64String("some text contents".getBytes()); attachment2.setData(data); Foo foo=new Foo(); Map<String,Attachment> attachments=new HashMap<String,Attachment>(); attachments.put("foo.txt",attachment1); attachments.put("foo2.txt",attachment2); foo.set_attachments(attachments); dbClient.save(foo); Bar bar=new Bar(); bar.addAttachment("bar.txt",attachment1); bar.addAttachment("bar2.txt",attachment2); dbClient.save(bar); }
Example 73
From project lor-jamwiki, under directory /jamwiki-core/src/main/java/org/jamwiki/utils/.
Source file: Encryption.java

/** * Encrypt a String value using the DES encryption algorithm. * @param unencryptedBytes The unencrypted String value that is to be encrypted. * @return An encrypted version of the String that was passed to this method. */ private static String encrypt64(byte[] unencryptedBytes) throws GeneralSecurityException, UnsupportedEncodingException { if (unencryptedBytes == null || unencryptedBytes.length == 0) { throw new IllegalArgumentException("Cannot encrypt a null or empty byte array"); } SecretKey key=createKey(); Cipher cipher=Cipher.getInstance(key.getAlgorithm()); cipher.init(Cipher.ENCRYPT_MODE,key); byte[] encryptedBytes=Base64.encodeBase64(cipher.doFinal(unencryptedBytes)); return bytes2String(encryptedBytes); }
Example 74
From project lorsource, under directory /src/main/java/ru/org/linux/csrf/.
Source file: CSRFProtectionService.java

public static void generateCSRFCookie(HttpServletRequest request,HttpServletResponse response){ SecureRandom random=new SecureRandom(); byte[] value=new byte[16]; random.nextBytes(value); String token=new String(Base64.encodeBase64(value)); Cookie cookie=new Cookie(CSRF_COOKIE,token); cookie.setMaxAge(TWO_YEARS); cookie.setPath("/"); response.addCookie(cookie); request.setAttribute(CSRF_ATTRIBUTE,token); }
Example 75
From project LRJavaLib, under directory /src/com/navnorth/learningregistry/.
Source file: LRClient.java

public static HttpResponse executeJsonPost(String url,StringEntity se,String username,String password) throws Exception { BufferedReader in=null; try { URI uri=URIfromURLString(url); HttpClient client=getHttpClient(uri.getScheme()); HttpPost post=new HttpPost(uri); post.setEntity(se); post.setHeader("Content-Type","application/json"); if (username != null && password != null) { String userPass=username + ":" + password; byte[] encodedAuth=Base64.encodeBase64(userPass.getBytes()); String encodedAuthStr=new String(encodedAuth); post.addHeader("Authorization","Basic " + encodedAuthStr); } HttpResponse response=client.execute(post); return response; } catch ( Exception e) { throw (e); } finally { if (in != null) { try { in.close(); } catch ( IOException e) { e.printStackTrace(); } } } }
Example 76
From project lyo.server, under directory /org.eclipse.lyo.server.oauth.consumerstore/src/main/java/org/eclipse/lyo/server/oauth/consumerstore/.
Source file: FileSystemConsumerStore.java

protected Resource toResource(LyoOAuthConsumer consumer) throws UnsupportedEncodingException { Resource resource=model.createResource(); resource.addProperty(RDF.type,model.createResource(CONSUMER_RESOURCE)); resource.addProperty(model.createProperty(CONSUMER_NAME),consumer.getName()); resource.addProperty(model.createProperty(CONSUMER_KEY),consumer.consumerKey); String encodedSecret=new String(Base64.encodeBase64(consumer.consumerSecret.getBytes("UTF8")),"UTF8"); resource.addProperty(model.createProperty(CONSUMER_SECRET),encodedSecret); resource.addProperty(model.createProperty(PROVISIONAL),(consumer.isProvisional()) ? "true" : "false"); resource.addProperty(model.createProperty(TRUSTED),(consumer.isTrusted()) ? "true" : "false"); return resource; }
Example 77
From project Mafiacraft, under directory /src/main/java/net/voxton/mafiacraft/core/util/.
Source file: StringSerializer.java

/** * Read the object from Base64 string. * @param string The string to deserialize. * @param type The type of object to deserialize into. * @return The deserialized object. */ public static <T extends Serializable>T fromString(String string,Class<T> type) throws IOException, ClassNotFoundException { byte[] data=Base64.decodeBase64(string); ByteArrayInputStream byteStream=new ByteArrayInputStream(data); ObjectInputStream objectStream=new ObjectInputStream(byteStream); Object o=objectStream.readObject(); objectStream.close(); return type.cast(o); }
Example 78
From project magrit, under directory /server/sshd/src/main/java/org/kercoin/magrit/sshd/auth/.
Source file: AuthorizedKeysDecoder.java

public PublicKey decodePublicKey(String keyLine) throws Exception { bytes=null; pos=0; for ( String part : keyLine.split(" ")) { if (part.startsWith("AAAA")) { bytes=Base64.decodeBase64(part); break; } } if (bytes == null) { throw new IllegalArgumentException("no Base64 part to decode"); } String type=decodeType(); if (type.equals("ssh-rsa")) { BigInteger e=decodeBigInt(); BigInteger m=decodeBigInt(); RSAPublicKeySpec spec=new RSAPublicKeySpec(m,e); return KeyFactory.getInstance("RSA").generatePublic(spec); } else if (type.equals("ssh-dss")) { BigInteger p=decodeBigInt(); BigInteger q=decodeBigInt(); BigInteger g=decodeBigInt(); BigInteger y=decodeBigInt(); DSAPublicKeySpec spec=new DSAPublicKeySpec(y,p,q,g); return KeyFactory.getInstance("DSA").generatePublic(spec); } else { throw new IllegalArgumentException("unknown type " + type); } }
Example 79
From project maven-wagon, under directory /wagon-tcks/wagon-tck-http/src/main/java/org/apache/maven/wagon/tck/http/fixture/.
Source file: AuthSnoopFilter.java

public void doFilter(final ServletRequest req,final ServletResponse response,final FilterChain chain) throws IOException, ServletException { HttpServletRequest request=(HttpServletRequest)req; String authHeader=request.getHeader("Authorization"); if (authHeader != null) { logger.info("Authorization: " + authHeader); String data=authHeader.substring("BASIC ".length()); String decoded=new String(Base64.decodeBase64(data)); logger.info(decoded); String[] creds=decoded.split(":"); logger.info("User: " + creds[0] + "\nPassword: "+ creds[1]); } }
Example 80
From project milton, under directory /milton/milton-api/src/main/java/com/bradmcevoy/http/.
Source file: Auth.java

private void parseBasic(String enc){ byte[] bytes; try { bytes=Base64.decodeBase64(enc.getBytes("UTF-8")); } catch ( UnsupportedEncodingException ex) { throw new RuntimeException(ex); } String s=new String(bytes); int pos=s.indexOf(":"); if (pos >= 0) { user=s.substring(0,pos); password=s.substring(pos + 1); } else { user=s; password=null; } }
Example 81
From project milton2, under directory /milton-api/src/main/java/io/milton/http/.
Source file: Auth.java

private void parseBasic(String enc){ byte[] bytes=Base64.decodeBase64(enc.getBytes()); String s=new String(bytes); int pos=s.indexOf(":"); if (pos >= 0) { user=s.substring(0,pos); password=s.substring(pos + 1); } else { user=s; password=null; } }
Example 82
From project moho, under directory /moho-remote/src/main/java/com/voxeo/rayo/client/auth/sasl/.
Source file: SASLMechanism.java

protected void authenticate() throws IOException, XmppException { String authenticationText=null; try { if (sc.hasInitialResponse()) { byte[] response=sc.evaluateChallenge(new byte[0]); authenticationText=Base64.encodeBase64String(response); } } catch ( SaslException e) { throw new XmppException("SASL authentication failed",e); } connection.send(new AuthMechanism(getName(),authenticationText)); }
Example 83
From project Mujina, under directory /mujina-common/src/main/java/nl/surfnet/mujina/model/.
Source file: CommonConfigurationImpl.java

private void injectKeyStore(String alias,String pemCert,String pemKey) throws Exception { CertificateFactory certFact; Certificate cert; String wrappedCert="-----BEGIN CERTIFICATE-----\n" + pemCert + "\n-----END CERTIFICATE-----"; ByteArrayInputStream certificateInputStream=new ByteArrayInputStream(wrappedCert.getBytes()); try { certFact=CertificateFactory.getInstance("X.509"); cert=certFact.generateCertificate(certificateInputStream); } catch ( CertificateException e) { throw new Exception("Could not instantiate cert",e); } IOUtils.closeQuietly(certificateInputStream); ArrayList<Certificate> certs=new ArrayList<Certificate>(); certs.add(cert); final byte[] key=Base64.decodeBase64(pemKey); KeyFactory keyFactory=KeyFactory.getInstance("RSA"); KeySpec ks=new PKCS8EncodedKeySpec(key); RSAPrivateKey privKey=(RSAPrivateKey)keyFactory.generatePrivate(ks); final Certificate[] certificates=new Certificate[1]; certificates[0]=certs.get(0); keyStore.setKeyEntry(alias,privKey,keystorePassword.toCharArray(),certificates); }
Example 84
From project NFC-Contact-Exchanger, under directory /src/a_vcard/android/syncml/pim/vcard/.
Source file: VCardComposer.java

/** * Build LOGO property. format LOGO's param and encode value as base64. * @param bytes the binary string to be converted * @param type the type of the content * @param version the version of vcard */ private void appendPhotoStr(byte[] bytes,String type,int version) throws VCardException { String value, encodingStr; try { value=foldingString(new String(Base64.encodeBase64(bytes,true)),version); } catch ( Exception e) { throw new VCardException(e.getMessage()); } if (isNull(type) || type.toUpperCase().indexOf("JPEG") >= 0) { type="JPEG"; } else if (type.toUpperCase().indexOf("GIF") >= 0) { type="GIF"; } else if (type.toUpperCase().indexOf("BMP") >= 0) { type="BMP"; } else { int indexOfSlash=type.indexOf("/"); if (indexOfSlash >= 0) { type=type.substring(indexOfSlash + 1).toUpperCase(); } else { type=type.toUpperCase(); } } mResult.append("LOGO;TYPE=").append(type); if (version == VERSION_VCARD21_INT) { encodingStr=";ENCODING=BASE64:"; value=value + mNewline; } else if (version == VERSION_VCARD30_INT) { encodingStr=";ENCODING=b:"; } else { return; } mResult.append(encodingStr).append(value).append(mNewline); }
Example 85
From project niosmtp, under directory /src/main/java/me/normanmaurer/niosmtp/delivery/chain/.
Source file: AbstractAuthResponseListener.java

@Override public List<String> getLines(){ List<String> lines=response.getLines(); if (lines != null && !lines.isEmpty()) { List<String> decodedLines=new ArrayList<String>(); for ( String line : lines) { decodedLines.add(new String(Base64.decodeBase64(line),CHARSET)); } return decodedLines; } return lines; }
Example 86
From project nutch, under directory /src/plugin/protocol-httpclient/src/java/org/apache/nutch/protocol/httpclient/.
Source file: HttpBasicAuthentication.java

/** * Construct an HttpBasicAuthentication for the given challenge parameters. The challenge parameters are returned by the web server using a WWW-Authenticate header. This will typically be represented by single line of the form <code>WWW-Authenticate: Basic realm="myrealm"</code> * @param challenge WWW-Authenticate header from web server */ protected HttpBasicAuthentication(String challenge,Configuration conf) throws HttpAuthenticationException { setConf(conf); this.challenge=challenge; credentials=new ArrayList(); String username=this.conf.get("http.auth.basic." + challenge + ".user"); String password=this.conf.get("http.auth.basic." + challenge + ".password"); if (LOG.isTraceEnabled()) { LOG.trace("BasicAuthentication challenge is " + challenge); LOG.trace("BasicAuthentication username=" + username); LOG.trace("BasicAuthentication password=" + password); } if (username == null) { throw new HttpAuthenticationException("Username for " + challenge + " is null"); } if (password == null) { throw new HttpAuthenticationException("Password for " + challenge + " is null"); } byte[] credBytes=(username + ":" + password).getBytes(); credentials.add("Authorization: Basic " + new String(Base64.encodeBase64(credBytes))); if (LOG.isTraceEnabled()) { LOG.trace("Basic credentials: " + credentials); } }
Example 87
From project nuxeo-distribution, under directory /nuxeo-startup-wizard/src/main/java/org/nuxeo/wizard/.
Source file: RouterServlet.java

public void handleConnectCallbackGET(Page currentPage,HttpServletRequest req,HttpServletResponse resp) throws ServletException, IOException { String token=req.getParameter(CONNECT_TOKEN_KEY); String action=req.getParameter("action"); String targetNav=null; if (action == null || action.isEmpty()) { action="skip"; } if (action.equals("register") && (token == null || token.isEmpty())) { action="skip"; } if ("register".equals(action)) { Map<String,String> connectMap=new HashMap<String,String>(); if (token != null) { String tokenData=new String(Base64.decodeBase64(token)); String[] tokenDataLines=tokenData.split("\n"); for ( String line : tokenDataLines) { String[] parts=line.split(":"); if (parts.length > 1) { connectMap.put(parts[0],parts[1]); } } Context.instance(req).storeConnectMap(connectMap); } SimpleNavigationHandler.instance().deactivatePage("ConnectFinish"); targetNav=currentPage.next().getAction(); } else if ("skip".equals(action)) { SimpleNavigationHandler.instance().activatePage("ConnectFinish"); targetNav=currentPage.next().getAction(); } else if ("prev".equals(action)) { targetNav=currentPage.prev().prev().getAction(); } String targetUrl=req.getContextPath() + "/" + targetNav; req.setAttribute("targetUrl",targetUrl); handleDefaultGET(currentPage,req,resp); }
Example 88
From project nuxeo-opensocial, under directory /nuxeo-opensocial-server/src/main/java/org/nuxeo/opensocial/service/impl/.
Source file: OpenSocialServiceImpl.java

public void setupOpenSocial() throws Exception { if (os == null) { log.warn("OpenSocial does not have any configuration contribution ... setup canceled"); return; } if (StringUtils.isBlank(os.getSigningKey())) { byte[] b64=Base64.encodeBase64(Crypto.getRandomBytes(BasicBlobCrypter.MASTER_KEY_MIN_LEN)); os.setSigningKey(new String(b64,"UTF-8")); } try { signingStateKeyFile=createTempFileForAKey(os.getSigningKey()); System.setProperty("shindig.signing.state-key",signingStateKeyFile.getPath()); } catch ( IOException e) { log.warn("ignoring signing key " + os.getSigningKey() + " because we cannot write temp file!",e); } if (!StringUtils.isBlank(os.getCallbackUrl())) { System.setProperty("shindig.signing.global-callback-url",os.getCallbackUrl()); } else { throw new Exception("Unable to start because the global callback url" + " is not set. See default-opensocial-config.xml"); } }
Example 89
From project nuxeo-platform-login, under directory /nuxeo-platform-login-digest/src/main/java/org/nuxeo/ecm/ui/web/auth/digest/.
Source file: DigestAuthenticator.java

@Override public Boolean handleLoginPrompt(HttpServletRequest httpRequest,HttpServletResponse httpResponse,String baseURL){ long expiryTime=System.currentTimeMillis() + (nonceValiditySeconds * 1000); String signature=DigestUtils.md5Hex(expiryTime + ":" + accessKey); String nonce=expiryTime + ":" + signature; String nonceB64=new String(Base64.encodeBase64(nonce.getBytes())); String authenticateHeader=String.format("Digest realm=\"%s\", qop=\"auth\", nonce=\"%s\"",realmName,nonceB64); try { httpResponse.addHeader(BA_HEADER_NAME,authenticateHeader); httpResponse.sendError(HttpServletResponse.SC_UNAUTHORIZED); return Boolean.TRUE; } catch ( IOException e) { return Boolean.FALSE; } }
Example 90
From project OAuth2.0ProviderForJava, under directory /provider/src/main/java/net/oauth/v2/.
Source file: SimpleOAuth2Validator.java

/** * Throw an exception if Basic Authentication has been validated. */ protected void validateBasicAuthentication(OAuth2Message message,OAuth2Accessor accessor) throws IOException, OAuth2Exception { String authz=message.getHeader("Authorization"); if (authz != null) { if (authz.substring(0,5).equals("Basic")) { String userPass=new String(Base64.decodeBase64(authz.substring(6).getBytes()),"UTF-8"); int loc=userPass.indexOf(":"); if (loc == -1) { OAuth2ProblemException problem=new OAuth2ProblemException(OAuth2.ErrorCode.INVALID_CLIENT); throw problem; } String userPassedIn=userPass.substring(0,loc); String user=userPassedIn; String pass=userPass.substring(loc + 1); if (user != null && pass != null) { if (!user.equals(accessor.client.clientId)) { OAuth2ProblemException problem=new OAuth2ProblemException(OAuth2.ErrorCode.INVALID_CLIENT); throw problem; } else { if (!pass.equals(accessor.client.clientSecret)) { OAuth2ProblemException problem=new OAuth2ProblemException(OAuth2.ErrorCode.INVALID_CLIENT); throw problem; } return; } } } } }
Example 91
From project onebusaway-nyc, under directory /onebusaway-nyc-presentation/src/main/java/org/onebusaway/nyc/geocoder/impl/.
Source file: GoogleGeocoderImpl.java

/** * PRIVATE METHODS */ private String signRequest(String key,String resource) throws NoSuchAlgorithmException, InvalidKeyException, UnsupportedEncodingException, URISyntaxException { key=key.replace('-','+'); key=key.replace('_','/'); byte[] base64edKey=Base64.decodeBase64(key.getBytes()); SecretKeySpec sha1Key=new SecretKeySpec(base64edKey,"HmacSHA1"); Mac mac=Mac.getInstance("HmacSHA1"); mac.init(sha1Key); byte[] sigBytes=mac.doFinal(resource.getBytes()); String signature=new String(Base64.encodeBase64(sigBytes)); signature=signature.replace('+','-'); signature=signature.replace('/','_'); return resource + "&signature=" + signature; }
Example 92
From project Openbravo-POS-iPhone-App, under directory /UnicentaPOS/src-pos/com/openbravo/pos/util/.
Source file: Base64Encoder.java

public static byte[] decode(String base64){ try { return Base64.decodeBase64(base64.getBytes("ASCII")); } catch ( UnsupportedEncodingException e) { return null; } }