use of sun.misc.BASE64Encoder in project fc-java-sdk by aliyun.
the class Code method setDir.
public Code setDir(String dir) throws IOException {
String tempZipPath = "/tmp/code" + UUID.randomUUID() + ".zip";
ZipUtils.zipDir(new File(dir), tempZipPath);
File file = new File(tempZipPath);
byte[] buffer = new byte[file.length() > Integer.MAX_VALUE ? Integer.MAX_VALUE : (int) file.length()];
FileInputStream fis = new FileInputStream(tempZipPath);
fis.read(buffer);
fis.close();
this.zipFile = new BASE64Encoder().encode(buffer);
new File(tempZipPath).delete();
return this;
}
use of sun.misc.BASE64Encoder in project ignite by apache.
the class JettyRestProcessorSignedSelfTest method signature.
/** {@inheritDoc} */
@Override
protected String signature() throws Exception {
long ts = U.currentTimeMillis();
String s = ts + ":" + REST_SECRET_KEY;
try {
MessageDigest md = MessageDigest.getInstance("SHA-1");
BASE64Encoder enc = new BASE64Encoder();
md.update(s.getBytes());
String hash = enc.encode(md.digest());
return ts + ":" + hash;
} catch (NoSuchAlgorithmException e) {
throw new Exception("Failed to create authentication signature.", e);
}
}
use of sun.misc.BASE64Encoder in project ignite by apache.
the class GridRestProtocolAdapter method authenticate.
/**
* Authenticates current request.
* <p>
* Token consists of 2 parts separated by semicolon:
* <ol>
* <li>Timestamp (time in milliseconds)</li>
* <li>Base64 encoded SHA1 hash of {1}:{secretKey}</li>
* </ol>
*
* @param tok Authentication token.
* @return {@code true} if authentication info provided in request is correct.
*/
protected boolean authenticate(@Nullable String tok) {
if (F.isEmpty(secretKey))
return true;
if (F.isEmpty(tok))
return false;
StringTokenizer st = new StringTokenizer(tok, ":");
if (st.countTokens() != 2)
return false;
String ts = st.nextToken();
String hash = st.nextToken();
String s = ts + ':' + secretKey;
try {
MessageDigest md = MessageDigest.getInstance("SHA-1");
BASE64Encoder enc = new BASE64Encoder();
md.update(s.getBytes(UTF_8));
String compHash = enc.encode(md.digest());
return hash.equalsIgnoreCase(compHash);
} catch (NoSuchAlgorithmException e) {
U.error(log, "Failed to check authentication signature.", e);
}
return false;
}
use of sun.misc.BASE64Encoder in project sakuli by ConSol.
the class ScreenshotDivConverter method extractScreenshotAsBase64.
protected String extractScreenshotAsBase64(Throwable exception) {
if (exception instanceof SakuliExceptionWithScreenshot) {
Path screenshotPath = ((SakuliExceptionWithScreenshot) exception).getScreenshot();
if (screenshotPath != null) {
try {
byte[] binaryScreenshot = Files.readAllBytes(screenshotPath);
String base64String = new BASE64Encoder().encode(binaryScreenshot);
for (String newLine : Arrays.asList("\n", "\r")) {
base64String = StringUtils.remove(base64String, newLine);
}
return base64String;
} catch (IOException e) {
exceptionHandler.handleException(new SakuliForwarderException(e, String.format("error during the BASE64 encoding of the screenshot '%s'", screenshotPath.toString())));
}
}
}
return null;
}
use of sun.misc.BASE64Encoder in project bazel by bazelbuild.
the class SignedJarBuilder method writeSignatureFile.
/** Writes a .SF file with a digest to the manifest. */
private void writeSignatureFile(SignatureOutputStream out) throws IOException, GeneralSecurityException {
Manifest sf = new Manifest();
Attributes main = sf.getMainAttributes();
main.putValue("Signature-Version", "1.0");
main.putValue("Created-By", "1.0 (Android)");
BASE64Encoder base64 = new BASE64Encoder();
MessageDigest md = MessageDigest.getInstance(DIGEST_ALGORITHM);
PrintStream print = new PrintStream(new DigestOutputStream(new ByteArrayOutputStream(), md), true, SdkConstants.UTF_8);
// Digest of the entire manifest
mManifest.write(print);
print.flush();
main.putValue(DIGEST_MANIFEST_ATTR, base64.encode(md.digest()));
Map<String, Attributes> entries = mManifest.getEntries();
for (Map.Entry<String, Attributes> entry : entries.entrySet()) {
// Digest of the manifest stanza for this entry.
print.print("Name: " + entry.getKey() + "\r\n");
for (Map.Entry<Object, Object> att : entry.getValue().entrySet()) {
print.print(att.getKey() + ": " + att.getValue() + "\r\n");
}
print.print("\r\n");
print.flush();
Attributes sfAttr = new Attributes();
sfAttr.putValue(DIGEST_ATTR, base64.encode(md.digest()));
sf.getEntries().put(entry.getKey(), sfAttr);
}
sf.write(out);
// As a workaround, add an extra CRLF in this case.
if ((out.size() % 1024) == 0) {
out.write('\r');
out.write('\n');
}
}
Aggregations