org.apache.commons.net.util.Base64 Java Examples
The following examples show how to use
org.apache.commons.net.util.Base64.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: CryptoUtil.java From datasync with MIT License | 6 votes |
public static String obfuscate(String s) { if(s == null) return null; try { ByteArrayOutputStream baos = new ByteArrayOutputStream(); baos.write(obfuscatedPrefix); try(CipherOutputStream cos = new CipherOutputStream(baos, cipher(Cipher.ENCRYPT_MODE, writeIv(baos))); OutputStreamWriter osw = new OutputStreamWriter(cos, StandardCharsets.UTF_8)) { osw.write(s); } return Base64.encodeBase64URLSafeString(baos.toByteArray()); } catch(Exception e) { throw new RuntimeException("Unexpected error", e); } }
Example #2
Source File: SftpClient.java From ats-framework with Apache License 2.0 | 6 votes |
@Override public int check( String host, byte[] key ) { host = host.replace("[", "").replace("]", "").split(":")[0]; // get only the IP address of the server if (knownHostsMap.get(host) == null) { log.error("The presented trust store certificates could not match any of the server provided ones"); return HostKeyRepository.NOT_INCLUDED; } Set<byte[]> keys = knownHostsMap.get(host); for (byte[] key1 : keys) { key1 = Base64.decodeBase64(key1); // we must decode the key from the client trust store first if (Arrays.equals(key, key1)) { log.info("Server certificate trusted."); return HostKeyRepository.OK; } } log.error("The presented trust store certificates could not match any of the server provided ones"); return HostKeyRepository.NOT_INCLUDED; }
Example #3
Source File: AbstractStorageManager.java From incubator-tajo with Apache License 2.0 | 6 votes |
/** * Get Disk Ids by Volume Bytes */ private int[] getDiskIds(VolumeId[] volumeIds) { int[] diskIds = new int[volumeIds.length]; for (int i = 0; i < volumeIds.length; i++) { int diskId = -1; if (volumeIds[i] != null && volumeIds[i].isValid()) { String volumeIdString = volumeIds[i].toString(); byte[] volumeIdBytes = Base64.decodeBase64(volumeIdString); if (volumeIdBytes.length == 4) { diskId = Bytes.toInt(volumeIdBytes); } else if (volumeIdBytes.length == 1) { diskId = (int) volumeIdBytes[0]; // support hadoop-2.0.2 } } diskIds[i] = diskId; } return diskIds; }
Example #4
Source File: MetadataWriterFactory.java From navigator-sdk with Apache License 2.0 | 6 votes |
private HttpURLConnection createHttpStream() throws IOException { String apiUrl = joinUrlPath( joinUrlPath(config.getNavigatorUrl(), "api/v" + String.valueOf(config.getApiVersion())), "metadata/plugin"); HttpURLConnection conn = openConnection(new URL(apiUrl)); conn.setRequestMethod("POST"); String userpass = config.getUsername() + ":" + config.getPassword(); String basicAuth = "Basic " + new String(Base64.encodeBase64( userpass.getBytes())); conn.addRequestProperty("Authorization", basicAuth); conn.addRequestProperty("Content-Type", "application/json"); conn.setDoOutput(true); return conn; }
Example #5
Source File: FixedValueSerializer.java From deeplearning4j with Apache License 2.0 | 6 votes |
@Override public void serialize(FixedValue fixedValue, JsonGenerator j, SerializerProvider serializerProvider) throws IOException { Object o = fixedValue.getValue(); j.writeStringField("@valueclass", o.getClass().getName()); if(o instanceof Number || o instanceof String || o instanceof Enum){ j.writeObjectField("value", o); } else { ByteArrayOutputStream baos = new ByteArrayOutputStream(); ObjectOutputStream oos = new ObjectOutputStream(baos); oos.writeObject(o); baos.close(); byte[] b = baos.toByteArray(); String base64 = new Base64().encodeToString(b); j.writeStringField("data", base64); } }
Example #6
Source File: AndroidSenseEnrollment.java From product-iots with Apache License 2.0 | 6 votes |
@BeforeClass(alwaysRun = true, groups = { Constants.UserManagement.USER_MANAGEMENT_GROUP}) public void initTest() throws Exception { super.init(userMode); User currentUser = getAutomationContext().getContextTenant().getContextUser(); byte[] bytesEncoded = Base64 .encodeBase64((currentUser.getUserName() + ":" + currentUser.getPassword()).getBytes()); String encoded = new String(bytesEncoded); String auth_string = "Basic " + encoded; String anaytics_https_url = automationContext.getContextUrls().getWebAppURLHttps() .replace("9443", String.valueOf(Constants.HTTPS_ANALYTICS_PORT)) .replace("/t/" + automationContext.getContextTenant().getDomain(), "") + "/"; this.client = new RestClient(backendHTTPSURL, Constants.APPLICATION_JSON, accessTokenString); this.analyticsClient = new RestClient(anaytics_https_url, Constants.APPLICATION_JSON, auth_string); if (this.userMode == TestUserMode.TENANT_ADMIN) { HttpResponse response = client .post(Constants.AndroidSenseEnrollment.ANALYTICS_ARTIFACTS_DEPLOYMENT_ENDPOINT, ""); Assert.assertEquals(HttpStatus.SC_CREATED, response.getResponseCode()); } }
Example #7
Source File: Nd4jBase64.java From nd4j with Apache License 2.0 | 5 votes |
/** * Returns a tab delimited base 64 * representation of the given arrays * @param arrays the arrays * @return * @throws IOException */ public static String arraysToBase64(INDArray[] arrays) throws IOException { StringBuilder sb = new StringBuilder(); //tab separate the outputs for de serialization for (INDArray outputArr : arrays) { ByteArrayOutputStream bos = new ByteArrayOutputStream(); DataOutputStream dos = new DataOutputStream(bos); Nd4j.write(outputArr, dos); String base64 = Base64.encodeBase64String(bos.toByteArray()); sb.append(base64); sb.append("\t"); } return sb.toString(); }
Example #8
Source File: Nd4jBase64.java From nd4j with Apache License 2.0 | 5 votes |
/** * Returns a set of arrays * from base 64 that is tab delimited. * @param base64 the base 64 that's tab delimited * @return the set of arrays */ public static INDArray[] arraysFromBase64(String base64) throws IOException { String[] base64Arr = base64.split("\t"); INDArray[] ret = new INDArray[base64Arr.length]; for (int i = 0; i < base64Arr.length; i++) { byte[] decode = Base64.decodeBase64(base64Arr[i]); ByteArrayInputStream bis = new ByteArrayInputStream(decode); DataInputStream dis = new DataInputStream(bis); INDArray predict = Nd4j.read(dis); ret[i] = predict; } return ret; }
Example #9
Source File: CubeDesc.java From Kylin with Apache License 2.0 | 5 votes |
public String calculateSignature() { MessageDigest md = null; try { md = MessageDigest.getInstance("MD5"); StringBuilder sigString = new StringBuilder(); sigString.append(this.name).append("|").append(this.getFactTable()).append("|").append(JsonUtil.writeValueAsString(this.model.getPartitionDesc())).append("|").append(JsonUtil.writeValueAsString(this.dimensions)).append("|").append(JsonUtil.writeValueAsString(this.measures)).append("|").append(JsonUtil.writeValueAsString(this.rowkey)).append("|").append(JsonUtil.writeValueAsString(this.hbaseMapping)); byte[] signature = md.digest(sigString.toString().getBytes()); return new String(Base64.encodeBase64(signature)); } catch (NoSuchAlgorithmException | JsonProcessingException e) { throw new RuntimeException("Failed to calculate signature"); } }
Example #10
Source File: Nd4jBase64.java From nd4j with Apache License 2.0 | 5 votes |
/** * Create an ndarray from a base 64 * representation * @param base64 the base 64 to convert * @return the ndarray from base 64 * @throws IOException */ public static INDArray fromBase64(String base64) throws IOException { byte[] arr = Base64.decodeBase64(base64); ByteArrayInputStream bis = new ByteArrayInputStream(arr); DataInputStream dis = new DataInputStream(bis); INDArray predict = Nd4j.read(dis); return predict; }
Example #11
Source File: DbfsServiceImpl.java From databricks-rest-client with Apache License 2.0 | 5 votes |
private void addBlocks(InputStream inputStream, long handle) throws IOException, DatabricksRestException { if (handle != 0L) { byte[] buffer = new byte[1024 * 1024]; int read; while ((read = inputStream.read(buffer)) > -1) { String data = Base64.encodeBase64String(Arrays.copyOf(buffer, read)); Map<String, Object> params = new HashMap<>(); params.put("handle", handle); params.put("data", data); client.performQuery(RequestMethod.POST, "/dbfs/add-block", params); } closeHandle(handle); } }
Example #12
Source File: LineageExport.java From navigator-sdk with Apache License 2.0 | 5 votes |
private HttpURLConnection createHttpConnection(ClientConfig config, Set<String> entityIds) throws IOException { String navUrl = config.getNavigatorUrl(); String serverUrl = navUrl + (navUrl.endsWith("/") ? LINEAGE_EXPORT_API : "/" + LINEAGE_EXPORT_API); String queryParamString = String.format(LINEAGE_EXPORT_API_QUERY_PARAMS, URLEncoder.encode(direction, charset), // direction of lineage URLEncoder.encode(length, charset), // length of lineage URLEncoder.encode(lineageOptions, charset)); // Apply all filters URL url = new URL(serverUrl + queryParamString); HttpURLConnection conn = (HttpURLConnection) url.openConnection(); String userpass = config.getUsername() + ":" + config.getPassword(); String basicAuth = "Basic " + new String(Base64.encodeBase64( userpass.getBytes())); conn.addRequestProperty("Authorization", basicAuth); conn.addRequestProperty("Content-Type", "application/json"); conn.addRequestProperty("Accept", "application/json"); conn.setReadTimeout(0); conn.setRequestMethod("POST"); // entityIds to pass in the request body String postData = constructEntityIdsAsCSV(entityIds); postData = "[" + postData + "]"; byte[] postDataBytes = postData.toString().getBytes("UTF-8"); conn.addRequestProperty("Content-Length", "" + Integer.toString(postData.getBytes().length)); conn.setDoOutput(true); conn.getOutputStream().write(postDataBytes); return conn; }
Example #13
Source File: TestBase.java From product-iots with Apache License 2.0 | 5 votes |
protected void init(TestUserMode userMode) throws Exception { automationContext = new AutomationContext(Constants.AUTOMATION_CONTEXT, userMode); String tenantDomain = automationContext.getContextTenant().getDomain(); backendHTTPSURL = automationContext.getContextUrls().getWebAppURLHttps().replace("9443", String.valueOf(Constants .HTTPS_GATEWAY_PORT)).replace("/t/" + tenantDomain , ""); backendHTTPURL = automationContext.getContextUrls().getWebAppURL().replace("9763", String.valueOf(Constants .HTTP_GATEWAY_PORT)).replace("/t/" + tenantDomain , ""); User currentUser = getAutomationContext().getContextTenant().getContextUser(); byte[] bytesEncoded = Base64 .encodeBase64((currentUser.getUserName() + ":" + currentUser.getPassword()).getBytes()); String encoded = new String(bytesEncoded); accessToken = OAuthUtil.getOAuthTokenPair(encoded, backendHTTPSURL, backendHTTPSURL, currentUser.getUserName(), currentUser.getPassword()); accessTokenString = "Bearer " + accessToken; }
Example #14
Source File: Nd4jBase64.java From deeplearning4j with Apache License 2.0 | 5 votes |
/** * Create an ndarray from a base 64 * representation * @param base64 the base 64 to convert * @return the ndarray from base 64 */ public static INDArray fromBase64(String base64) { byte[] arr = Base64.decodeBase64(base64); ByteArrayInputStream bis = new ByteArrayInputStream(arr); DataInputStream dis = new DataInputStream(bis); return Nd4j.read(dis); }
Example #15
Source File: UpdateVPCCmd.java From cosmic with Apache License 2.0 | 5 votes |
public ComplianceStatus getComplianceStatus() { if (complianceStatus == null || complianceStatus.isEmpty()) { return null; } if (getHttpMethod() == HTTPMethod.POST) { complianceStatus = new String(Base64.decodeBase64(this.complianceStatus)); } return ComplianceStatus.valueOf(complianceStatus); }
Example #16
Source File: UpdateVMCmd.java From cosmic with Apache License 2.0 | 5 votes |
public ComplianceStatus getComplianceStatus() { if (complianceStatus == null || complianceStatus.isEmpty()) { return null; } if (getHttpMethod() == HTTPMethod.POST) { complianceStatus = new String(Base64.decodeBase64(this.complianceStatus)); } return ComplianceStatus.valueOf(complianceStatus); }
Example #17
Source File: UpdateVMCmd.java From cosmic with Apache License 2.0 | 5 votes |
public OptimiseFor getOptimiseFor() { if (optimiseFor != null) { if (getHttpMethod() == HTTPMethod.POST) { optimiseFor = new String(Base64.decodeBase64(this.optimiseFor)); } return OptimiseFor.valueOf(optimiseFor); } else { return OptimiseFor.Generic; } }
Example #18
Source File: RecordChecksum.java From Scribengin with GNU Affero General Public License v3.0 | 4 votes |
public String getKeyDigestAsBase64() { invalidUpdateState = true; return Base64.encodeBase64String(keyDigest.digest()); }
Example #19
Source File: RecordChecksum.java From Scribengin with GNU Affero General Public License v3.0 | 4 votes |
public String getDataDigestAsBase64() { invalidUpdateState = true; return Base64.encodeBase64String(dataDigest.digest()); }
Example #20
Source File: HttpUtility.java From datasync with MIT License | 4 votes |
private String getAuthHeader(String username, String password) { String auth = username + ":" + password; byte[] encodedAuth = Base64.encodeBase64(auth.getBytes(Charset.forName("US-ASCII"))); return "Basic " + new String(encodedAuth); }
Example #21
Source File: JsonLineSerializer.java From tajo with Apache License 2.0 | 4 votes |
private void putValue(JSONObject json, String fullPath, String [] pathElements, int depth, int fieldIndex, Tuple input) throws IOException { String fieldName = pathElements[depth]; if (input.isBlankOrNull(fieldIndex)) { return; } switch (types.get(fullPath)) { case BOOLEAN: json.put(fieldName, input.getBool(fieldIndex)); break; case INT1: case INT2: json.put(fieldName, input.getInt2(fieldIndex)); break; case INT4: json.put(fieldName, input.getInt4(fieldIndex)); break; case INT8: json.put(fieldName, input.getInt8(fieldIndex)); break; case FLOAT4: json.put(fieldName, input.getFloat4(fieldIndex)); break; case FLOAT8: json.put(fieldName, input.getFloat8(fieldIndex)); break; case TEXT: case VARCHAR: json.put(fieldName, input.getText(fieldIndex)); break; case CHAR: case DATE: case INTERVAL: json.put(fieldName, input.asDatum(fieldIndex).asChars()); break; case TIMESTAMP: json.put(fieldName, TimestampDatum.asChars(input.getTimeDate(fieldIndex), timezone, false)); break; case TIME: json.put(fieldName, input.asDatum(fieldIndex).asChars()); break; case BIT: case BINARY: case BLOB: case VARBINARY: json.put(fieldName, Base64.encodeBase64String(input.getBytes(fieldIndex))); break; case NULL_TYPE: break; case RECORD: JSONObject record = json.containsKey(fieldName) ? (JSONObject) json.get(fieldName) : new JSONObject(); json.put(fieldName, record); putValue(record, fullPath + "/" + pathElements[depth + 1], pathElements, depth + 1, fieldIndex, input); break; default: throw new TajoRuntimeException( new NotImplementedException("" + types.get(fullPath).name() + " for json")); } }
Example #22
Source File: TftpServerTester.java From tftp4j with Apache License 2.0 | 4 votes |
public void run() throws Exception { client.open(); provider.setData("/hello", "Hello, world."); assertFails("/nonexistent", TFTPClient.BINARY_MODE); assertFails("/nonexistent", TFTPClient.ASCII_MODE); assertSucceeds("/hello", TFTPClient.BINARY_MODE); assertSucceeds("/hello", TFTPClient.ASCII_MODE); int[] sizes = new int[]{ 0, 1, 8, 511, 512, 513, 1 * 1024 - 1, 1 * 1024, 1 * 1024 + 1, 4 * 1024 - 1, 4 * 1024, 4 * 1024 + 1, 1024 * 1024 - 1, 1024 * 1024, 1024 * 1024 + 1 }; for (int size : sizes) { byte[] data = newRandomBytes(size); provider.setData("/binary", data); assertSucceeds("/binary", TFTPClient.BINARY_MODE); provider.setData("/ascii", Base64.encodeBase64(data)); assertSucceeds("/ascii", TFTPClient.ASCII_MODE); } client.close(); }
Example #23
Source File: EagleBase64Wrapper.java From eagle with Apache License 2.0 | 4 votes |
public static byte[] decode(String input) { return Base64.decodeBase64(input); }
Example #24
Source File: EagleBase64Wrapper.java From eagle with Apache License 2.0 | 4 votes |
public static String encodeByteArray2URLSafeString(byte[] bytes) { return Base64.encodeBase64URLSafeString(bytes); }
Example #25
Source File: EagleBase64Wrapper.java From Eagle with Apache License 2.0 | 4 votes |
public static byte[] decode(String input){ return Base64.decodeBase64(input); }
Example #26
Source File: EagleBase64Wrapper.java From Eagle with Apache License 2.0 | 4 votes |
public static String encodeByteArray2URLSafeString(byte[] bytes){ return Base64.encodeBase64URLSafeString(bytes); }
Example #27
Source File: HiveKuduTableInputFormat.java From HiveKudu-Handler with Apache License 2.0 | 4 votes |
@Override public void setConf(Configuration entries) { LOG.warn("I was called : setConf"); this.conf = new Configuration(entries); String tableName = conf.get(INPUT_TABLE_KEY); String masterAddresses = conf.get(MASTER_ADDRESSES_KEY); this.operationTimeoutMs = conf.getLong(OPERATION_TIMEOUT_MS_KEY, AsyncKuduClient.DEFAULT_OPERATION_TIMEOUT_MS); this.nameServer = conf.get(NAME_SERVER_KEY); this.cacheBlocks = conf.getBoolean(SCAN_CACHE_BLOCKS, false); LOG.warn(" the master address here is " + masterAddresses); this.client = new KuduClient.KuduClientBuilder(masterAddresses) .defaultOperationTimeoutMs(operationTimeoutMs) .build(); try { this.table = client.openTable(tableName); } catch (Exception ex) { throw new RuntimeException("Could not obtain the table from the master, " + "is the master running and is this table created? tablename=" + tableName + " and " + "master address= " + masterAddresses, ex); } //String projectionConfig = conf.get(COLUMN_PROJECTION_KEY); String projectionConfig = "id,name"; if (projectionConfig == null || projectionConfig.equals("*")) { this.projectedCols = null; // project the whole table } else if ("".equals(projectionConfig)) { this.projectedCols = new ArrayList<>(); } else { this.projectedCols = Lists.newArrayList(Splitter.on(',').split(projectionConfig)); // Verify that the column names are valid -- better to fail with an exception // before we submit the job. Schema tableSchema = table.getSchema(); for (String columnName : projectedCols) { if (tableSchema.getColumn(columnName) == null) { throw new IllegalArgumentException("Unknown column " + columnName); } } } String encodedPredicates = conf.get(ENCODED_COLUMN_RANGE_PREDICATES_KEY, ""); rawPredicates = Base64.decodeBase64(encodedPredicates); }
Example #28
Source File: APITokenConnectionAuthenticator.java From netbeans with Apache License 2.0 | 4 votes |
@Messages({"# {0} - server location", "# {1} - user name", "APITokenConnectionAuthenticator.password_description=API token for {1} on {0}"}) @org.netbeans.api.annotations.common.SuppressWarnings("DM_DEFAULT_ENCODING") @Override public URLConnection forbidden(URLConnection conn, URL home) { String version = conn.getHeaderField("X-Jenkins"); if (version == null) { if (conn.getHeaderField("X-Hudson") == null) { LOG.log(Level.FINE, "neither Hudson nor Jenkins headers on {0}, assuming might be Jenkins", home); } else { LOG.log(Level.FINE, "disabled on non-Jenkins server {0}", home); return null; } } else if (new HudsonVersion(version).compareTo(new HudsonVersion("1.426")) < 0) { LOG.log(Level.FINE, "disabled on old ({0}) Jenkins server {1}", new Object[] {version, home}); return null; } else { LOG.log(Level.FINE, "enabled on {0}", home); } APITokenConnectionAuthenticator panel = new APITokenConnectionAuthenticator(); String server = HudsonManager.simplifyServerLocation(home.toString(), true); String key = "tok." + server; String username = FormLogin.loginPrefs().get(server, null); if (username != null) { panel.userField.setText(username); char[] savedToken = Keyring.read(key); if (savedToken != null) { panel.tokField.setText(new String(savedToken)); } } panel.locationField.setText(home.toString()); DialogDescriptor dd = new DialogDescriptor(panel, Bundle.FormLogin_log_in()); if (DialogDisplayer.getDefault().notify(dd) != NotifyDescriptor.OK_OPTION) { return null; } username = panel.userField.getText(); LOG.log(Level.FINE, "trying token for {0} on {1}", new Object[] {username, home}); FormLogin.loginPrefs().put(server, username); String token = new String(panel.tokField.getPassword()); panel.tokField.setText(""); Keyring.save(key, token.toCharArray(), Bundle.APITokenConnectionAuthenticator_password_description(home, username)); BASIC_AUTH.put(home.toString(), new Base64(0).encodeToString((username + ':' + token).getBytes()).trim()); try { return conn.getURL().openConnection(); } catch (IOException x) { LOG.log(Level.FINE, null, x); return null; } }
Example #29
Source File: Nd4jBase64.java From nd4j with Apache License 2.0 | 3 votes |
/** * Returns an ndarray * as base 64 * @param arr the array to write * @return the base 64 representation of the binary * ndarray * @throws IOException */ public static String base64String(INDArray arr) throws IOException { ByteArrayOutputStream bos = new ByteArrayOutputStream(); DataOutputStream dos = new DataOutputStream(bos); Nd4j.write(arr, dos); String base64 = Base64.encodeBase64String(bos.toByteArray()); return base64; }
Example #30
Source File: Nd4jBase64.java From deeplearning4j with Apache License 2.0 | 3 votes |
/** * Returns an ndarray * as base 64 * @param arr the array to write * @return the base 64 representation of the binary * ndarray */ public static String base64String(INDArray arr) throws IOException { ByteArrayOutputStream bos = new ByteArrayOutputStream(); DataOutputStream dos = new DataOutputStream(bos); Nd4j.write(arr, dos); return Base64.encodeBase64String(bos.toByteArray()); }