use of sun.misc.BASE64Encoder in project blade by biezhi.
the class Tools method enAes.
public static String enAes(String data, String key) throws Exception {
Cipher cipher = Cipher.getInstance("AES");
SecretKeySpec secretKeySpec = new SecretKeySpec(key.getBytes("UTF-8"), "AES");
cipher.init(Cipher.ENCRYPT_MODE, secretKeySpec);
byte[] encryptedBytes = cipher.doFinal(data.getBytes());
return new BASE64Encoder().encode(encryptedBytes);
}
use of sun.misc.BASE64Encoder in project orientdb by orientechnologies.
the class OCommandExecutorSQLSelectTest method testBinaryField.
@Test
public void testBinaryField() {
//issue #6379
byte[] array = new byte[] { 1, 4, 5, 74, 3, 45, 6, 127, -120, 2 };
db.command(new OCommandSQL("create class TestBinaryField")).execute();
ODocument doc = db.newInstance("TestBinaryField");
doc.field("binaryField", array);
doc.save();
doc = db.newInstance("TestBinaryField");
doc.field("binaryField", "foobar");
doc.save();
String base64Value = new BASE64Encoder().encode(array);
List<ODocument> results = db.query(new OSQLSynchQuery<ODocument>("select from TestBinaryField where binaryField = decode(?, 'base64')"), base64Value);
assertEquals(results.size(), 1);
Object value = results.get(0).field("binaryField");
assertEquals(value, array);
}
use of sun.misc.BASE64Encoder in project atlas by alibaba.
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, "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');
}
}
use of sun.misc.BASE64Encoder in project CshBBrain by CshBBrain.
the class ClustersDecoder method base64Encode.
public static String base64Encode(byte[] input) {
BASE64Encoder encoder = new BASE64Encoder();
String base64 = encoder.encode(input);
return base64;
}
use of sun.misc.BASE64Encoder in project CshBBrain by CshBBrain.
the class WebSocketDecoder method base64Encode.
public static String base64Encode(byte[] input) {
BASE64Encoder encoder = new BASE64Encoder();
String base64 = encoder.encode(input);
return base64;
}
Aggregations