List of usage examples for org.apache.commons.codec.binary Base64 decodeBase64
public static byte[] decodeBase64(final byte[] base64Data)
From source file:com.vimukti.accounter.developer.api.PublicKeyGenerator.java
private static void generate() throws NoSuchAlgorithmException, NoSuchProviderException, InvalidKeySpecException, KeyStoreException, CertificateException, IOException, URISyntaxException { KeyPairGenerator keyGen = KeyPairGenerator.getInstance("DSA"); SecureRandom random = SecureRandom.getInstance("SHA1PRNG"); random.setSeed("VimTech".getBytes("UTF-8")); keyGen.initialize(1024, random);/*from ww w . j a va 2s. c om*/ KeyPair pair = keyGen.generateKeyPair(); PrivateKey priv = pair.getPrivate(); PublicKey pub = pair.getPublic(); System.out.println(priv); System.out.println(pub); byte[] encoded = pub.getEncoded(); byte[] encodeBase64 = Base64.encodeBase64(encoded); System.out.println("Public Key:" + new String(encodeBase64)); byte[] encodedPrv = priv.getEncoded(); byte[] encodeBase64Prv = Base64.encodeBase64(encodedPrv); System.out.println("Private Key:" + new String(encodeBase64Prv)); byte[] decodeBase64 = Base64.decodeBase64(encodeBase64); X509EncodedKeySpec pubKeySpec = new X509EncodedKeySpec(decodeBase64); KeyFactory keyFactory = KeyFactory.getInstance("DSA"); System.out.println(keyFactory.generatePublic(pubKeySpec).equals(pub)); }
From source file:de.scrubstudios.srvmon.agent.classes.Crypt.java
/** * This function is used to decrypt incoming data. * @param key Encryption key/*from w w w . j av a 2s . co m*/ * @param data Data string which should be decrypted. * @return The decrypted data string. */ public static String decrypt(String key, String data) { byte[] decryptedData = null; SecretKeySpec keySpec = new SecretKeySpec(key.getBytes(), "AES"); try { Cipher cipher = Cipher.getInstance("AES/ECB/PKCS5Padding"); cipher.init(Cipher.DECRYPT_MODE, keySpec); decryptedData = cipher.doFinal(Base64.decodeBase64(data)); return new String(decryptedData); } catch (NoSuchAlgorithmException | NoSuchPaddingException | InvalidKeyException | IllegalBlockSizeException | BadPaddingException ex) { Logger.getLogger(Crypt.class.getName()).log(Level.SEVERE, null, ex); } return null; }
From source file:com.mirth.connect.server.util.DICOMUtil.java
public static String mergeHeaderAttachments(MessageObject message, List<Attachment> attachments) throws SerializerException { try {/*from w w w .ja v a2 s. co m*/ List<byte[]> images = new ArrayList<byte[]>(); for (Attachment attachment : attachments) { images.add(Base64.decodeBase64(attachment.getData())); } byte[] headerBytes; if (message.getEncodedDataProtocol().equals(MessageObject.Protocol.DICOM) && message.getEncodedData() != null) { headerBytes = Base64.decodeBase64(message.getEncodedData().getBytes()); } else if (message.getRawDataProtocol().equals(MessageObject.Protocol.DICOM) && message.getRawData() != null) { headerBytes = Base64.decodeBase64(message.getRawData().getBytes()); } else { return StringUtils.EMPTY; } return mergeHeaderPixelData(headerBytes, images); } catch (IOException e) { throw new SerializerException(e); } }
From source file:com.rackspacecloud.blueflood.io.serializers.TimerSerializationTest.java
@Test public void testV1RoundTrip() throws IOException { // build up a Timer TimerRollup r0 = new TimerRollup().withSum(42).withCountPS(23.32d).withAverage(56).withVariance(853.3245d) .withMinValue(2).withMaxValue(987).withCount(345); r0.setPercentile("foo", 741.32d); r0.setPercentile("bar", 0.0323d); if (System.getProperty("GENERATE_TIMER_SERIALIZATION") != null) { OutputStream os = new FileOutputStream( "src/test/resources/serializations/timer_version_" + Constants.VERSION_1_TIMER + ".bin", false); os.write(Base64.encodeBase64(new NumericSerializer.TimerRollupSerializer().toByteBuffer(r0).array())); os.write("\n".getBytes()); os.close();/*www.j a v a 2s. c o m*/ } Assert.assertTrue(new File("src/test/resources/serializations").exists()); // ensure historical reads work. int version = 0; int maxVersion = Constants.VERSION_1_TIMER; int count = 0; while (version <= maxVersion) { BufferedReader reader = new BufferedReader( new FileReader("src/test/resources/serializations/timer_version_" + version + ".bin")); ByteBuffer bb = ByteBuffer.wrap(Base64.decodeBase64(reader.readLine().getBytes())); TimerRollup r1 = new NumericSerializer.TimerRollupSerializer().fromByteBuffer(bb); Assert.assertEquals(r0, r1); count++; version++; } Assert.assertTrue("Nothing was tested", count > 0); }
From source file:com.vmware.o11n.plugin.crypto.service.CryptoDigestService.java
/** * HmacMD5//w w w .j a va 2 s . c o m * * @param keyB64 Secret key Base64 encoded * @param dataB64 Data to sign Base64 encoded * @return HmacMd5 MAC for the given key and data Base64 encoded */ public String hmacMd5(String keyB64, String dataB64) { validateB64(keyB64); validateB64(dataB64); final byte[] key = Base64.decodeBase64(keyB64); final byte[] data = Base64.decodeBase64(dataB64); return Base64.encodeBase64String(HmacUtils.hmacMd5(key, data)); }
From source file:cn.org.once.cstack.utils.CustomPasswordEncoder.java
public String decode(CharSequence pass) { Cipher cipher;// w w w . j a va 2s . com String decryptString = null; try { byte[] encryptText = Base64.decodeBase64(pass.toString()); cipher = Cipher.getInstance(ALGO); cipher.init(Cipher.DECRYPT_MODE, generateKey()); decryptString = new String(cipher.doFinal(encryptText)); } catch (Exception e) { e.printStackTrace(); } return decryptString; }
From source file:com.kscs.server.web.source.XMLSourceCode.java
public static String getHibernateIDProperty() { return new String(Base64.decodeBase64(HIBERNATE_ID.getBytes())); }
From source file:com.jaspersoft.studio.server.protocol.restv2.CASUtil.java
public static String getToken(ServerProfile sp, IProgressMonitor monitor) throws Exception { String v = null;/*from w w w . j a v a 2 s . c om*/ v = JasperReportsConfiguration.getDefaultInstance().getPrefStore().getString(CASPreferencePage.CAS); for (String line : v.split("\n")) { if (line.isEmpty()) continue; SSOServer srv = null; try { srv = (SSOServer) CastorHelper.read(new ByteArrayInputStream(Base64.decodeBase64(line)), CASListFieldEditor.getMapping()); } catch (Exception e) { e.printStackTrace(); continue; } if (srv.getUuid().equals(sp.getSsoUuid())) return doGetTocken(sp, srv, monitor); } throw new Exception("Could not find SSO Server in the list."); }
From source file:de.mpg.mpdl.inge.aa.web.client.EscidocAaClientFinish.java
@Override protected AuthenticationVO finalizeAuthentication(HttpServletRequest request, HttpServletResponse response) throws Exception { String escidocUserHandle = request.getParameter("eSciDocUserHandle"); if (escidocUserHandle != null) { try {//w w w . j a v a2s.c o m escidocUserHandle = new String(Base64.decodeBase64(escidocUserHandle.getBytes())); UserAccountHandler userAccountHandler = ServiceLocator.getUserAccountHandler(escidocUserHandle); String accountData = userAccountHandler.retrieveCurrentUser(); AccountUserVO accountUserVO = new XmlTransformingBean().transformToAccountUser(accountData); String grantData = userAccountHandler .retrieveCurrentGrants(accountUserVO.getReference().getObjectId()); List<GrantVO> grants = new XmlTransformingBean().transformToGrantVOList(grantData); if (grants != null) { accountUserVO.getGrants().addAll(grants); } AuthenticationVO authenticationVO = new AuthenticationVO(); authenticationVO.setType(Type.USER); authenticationVO.setUsername(accountUserVO.getUserid()); authenticationVO.setUserId(accountUserVO.getReference().getObjectId()); authenticationVO.setFullName(accountUserVO.getName()); for (GrantVO grantVO : accountUserVO.getGrants()) { if (grantVO.getObjectRef() == null) { Role role = authenticationVO.new Role(); role.setKey(grantVO.getRole()); authenticationVO.getRoles().add(role); authenticationVO.getRoles().add(role); } else { Grant grant = authenticationVO.new Grant(); grant.setKey(grantVO.getRole()); grant.setValue(grantVO.getObjectRef()); authenticationVO.getGrants().add(grant); } } return authenticationVO; } catch (Exception e) { throw new ServletException(e); } } return null; }
From source file:com.cnd.greencube.web.base.util.RSAUtils.java
/** * /*w w w . jav a 2s. co m*/ * * @param privateKey * ? * @param text * Base64? * @return ?? */ public static String decrypt(PrivateKey privateKey, String text) { Assert.notNull(privateKey); Assert.notNull(text); byte[] data = decrypt(privateKey, Base64.decodeBase64(text)); return data != null ? new String(data) : null; }