Search in sources :

Example 11 with BASE64Encoder

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);
}
Also used : SecretKeySpec(javax.crypto.spec.SecretKeySpec) BASE64Encoder(sun.misc.BASE64Encoder) Cipher(javax.crypto.Cipher)

Example 12 with BASE64Encoder

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);
}
Also used : BASE64Encoder(sun.misc.BASE64Encoder) ODocument(com.orientechnologies.orient.core.record.impl.ODocument) Test(org.testng.annotations.Test)

Example 13 with BASE64Encoder

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');
    }
}
Also used : BASE64Encoder(sun.misc.BASE64Encoder) Map(java.util.Map)

Example 14 with BASE64Encoder

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;
}
Also used : BASE64Encoder(sun.misc.BASE64Encoder)

Example 15 with BASE64Encoder

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;
}
Also used : BASE64Encoder(sun.misc.BASE64Encoder)

Aggregations

BASE64Encoder (sun.misc.BASE64Encoder)20 MessageDigest (java.security.MessageDigest)6 File (java.io.File)3 ByteArrayOutputStream (java.io.ByteArrayOutputStream)2 FileOutputStream (java.io.FileOutputStream)2 IOException (java.io.IOException)2 PrintStream (java.io.PrintStream)2 KeyPair (java.security.KeyPair)2 KeyPairGenerator (java.security.KeyPairGenerator)2 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)2 PublicKey (java.security.PublicKey)2 X509Certificate (java.security.cert.X509Certificate)2 Calendar (java.util.Calendar)2 Date (java.util.Date)2 Map (java.util.Map)2 Attributes (java.util.jar.Attributes)2 Manifest (java.util.jar.Manifest)2 SecretKeySpec (javax.crypto.spec.SecretKeySpec)2 ODocument (com.orientechnologies.orient.core.record.impl.ODocument)1 ByteArrayInputStream (java.io.ByteArrayInputStream)1