Example usage for java.util Base64 getEncoder

List of usage examples for java.util Base64 getEncoder

Introduction

In this page you can find the example usage for java.util Base64 getEncoder.

Prototype

public static Encoder getEncoder() 

Source Link

Document

Returns a Encoder that encodes using the Basic type base64 encoding scheme.

Usage

From source file:org.apache.accumulo.test.util.SerializationUtil.java

public static String serializeWritableBase64(Writable writable) {
    byte[] b = serializeWritable(writable);
    return Base64.getEncoder().encodeToString(b);
}

From source file:com.antonjohansson.elasticsearchshell.client.PasswordEncrypter.java

/**
 * Encrypts the given password, using the username as salt.
 *
 * @param username The username, used for salt.
 * @param password The password to encrypt.
 * @return Returns the encrypted password.
 *///from   ww  w . j a va 2  s. c o  m
String encrypt(String username, String password) {
    try {
        String key = rightPad(username, KEY_SIZE).substring(0, KEY_SIZE);
        Key spec = new SecretKeySpec(key.getBytes(), algorithm);
        Cipher cipher = Cipher.getInstance(algorithm);
        cipher.init(ENCRYPT_MODE, spec);
        byte[] encrypted = cipher.doFinal(password.getBytes());
        return Base64.getEncoder().encodeToString(encrypted);
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
}

From source file:org.openwms.common.FeignConfiguration.java

public @Bean RequestInterceptor basicAuthRequestInterceptor() {
    return (t) -> {
        //Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
        //User user = (User) authentication.getPrincipal();
        String username = "user";//user.getUsername();
        String password = "sa";//(String) authentication.getCredentials();
        t.header("Authorization", "Basic " + Base64.getEncoder()
                .encodeToString((username + ":" + password).getBytes(Charset.forName("UTF-8"))));
        t.header(Constants.HEADER_VALUE_X_TENANT, TenantHolder.getCurrentTenant());
        String reqId = RequestIDHolder.getRequestID();
        if (reqId != null) {
            t.header(Constants.HEADER_VALUE_X_REQUESTID, reqId);
        }//from  ww  w . j  ava  2s  . c  o  m
    };
}

From source file:it.lic.cli.Main.java

private void run(final CommandLine cli) throws Exception {
    final Wallet wallet = new Wallet.Default(new FileStorage(new System.Default()));
    if (cli.hasOption("h")) {
        this.help();
    } else if (cli.hasOption("l")) {
        final LicenseKeyPair lkp = wallet.licenseKeyPair(cli.getOptionValue("l"));
        java.lang.System.out.println(String.format("[%s] Public key: %s", lkp.name(),
                new String(Base64.getEncoder().encode(lkp.publicKey().getEncoded()))));
    } else if (cli.hasOption("L")) {
        final Iterator<License> licenses = wallet.licenses(wallet.licenseKeyPair(cli.getOptionValue("L")), "");
        while (licenses.hasNext()) {
            License current = licenses.next();
            java.lang.System.out.println(String.format("%s\t%s\t%s\t%s", current.name(), current.issuer(),
                    current.until(), current.encode()));
        }//w  w w  .j a  va 2  s.  c  om
    } else if (cli.hasOption("k")) {
        final LicenseKeyPair lkp = wallet.newLicenseKeyPair(cli.getOptionValue("k"));
        java.lang.System.out.println(String.format("new keypair created: %s",
                new String(Base64.getEncoder().encode(lkp.publicKey().getEncoded()))));
    } else if (cli.hasOption("K")) {
        final Calendar expire = Calendar.getInstance();
        expire.add(Calendar.YEAR, 1);
        Optional<License> license = wallet.hasLicenseFor(wallet.licenseKeyPair("prometeo"),
                cli.getOptionValue("K"));
        if (license.isPresent()) {
            java.lang.System.out.println(String.format("license already esists: %s", license.get().encode()));
        } else {
            final License newlicense = wallet.newLicense(cli.getOptionValue("K"),
                    wallet.licenseKeyPair("prometeo"), cli.getOptionValue("K"), expire.getTime(),
                    Collections.emptyMap());
            java.lang.System.out.println(String.format("new license created: %s", newlicense.encode()));
        }
    }
}

From source file:ec.edu.chyc.manejopersonal.util.ServerUtils.java

/***
 * Devuelve un UUID generado y codificado en Base64
 *
 * @return Uuid codificado en Base64/*from w w w  . j ava  2  s . c om*/
 */
public static String generateB64Uuid() {
    UUID uuid = UUID.randomUUID();
    ByteBuffer uuidBytes = ByteBuffer.wrap(new byte[16]);
    uuidBytes.putLong(uuid.getMostSignificantBits()).putLong(uuid.getLeastSignificantBits());
    String asB64 = Base64.getEncoder().encodeToString(uuidBytes.array());
    return asB64;
}

From source file:azkaban.crypto.Crypto.java

public static String encode(String s) {
    return Base64.getEncoder().encodeToString(s.getBytes());
}

From source file:jp.co.opentone.bsol.framework.core.util.ConvertUtil.java

/**
 * BASE64???????.//from   w w  w  .j a  v a 2 s .co m
 * @param data ?
 * @return ??
 */
public static String toBase64String(byte[] data) {
    return Base64.getEncoder().encodeToString(data);
}

From source file:org.khannex.action.MakeSign.java

@Override
public Response execute(Context context) {
    Response retval = null;/*ww w  .j  a  va 2s.c o m*/

    final Optional<String> param = getNextParam();
    if (param.isPresent()) {
        final CardIO cardio = new CardIO();
        try {
            final byte[] digest = DigestUtils.sha1(param.get());
            final byte[] pin = readPin().getBytes();

            cardio.connect();
            cardio.transmitReset().assertSuccessful();
            cardio.transmitSelectDf(new byte[] { 0x50, 0x11 }).assertSuccessful();
            cardio.transmitSelectDf(new byte[] { (byte) 0x90, 0x02 }).assertSuccessful();
            cardio.transmitVerify(pin).assertSuccessful();
            cardio.transmitSelectPrivateKey().assertSuccessful();
            final byte[] signature = cardio.transmitSign(digest).assertSuccessful().getData();

            final String result = Base64.getEncoder().encodeToString(getBerEncodedResult(digest, signature));
            retval = response().withResult(result).build();
        } catch (Exception ex) {
            context.setException(ex);

            retval = response().build();
        } finally {
            cardio.disconnect();
        }
    }

    return retval;
}

From source file:Search.DataManipulation.DataParser.java

public String getIcon(Document dom) throws IOException {
    Elements iconClass = dom.getElementsByClass("cover-container");
    Elements iconClass1 = iconClass.select("img.cover-image[alt=Cover art]");
    String iconUrl = iconClass1.first().attr("src");
    byte[] iconByte = dataHandler.imageDownloader(iconUrl);

    if (iconByte.length == 0) {
        log.warn("Invalid Icon url found by Search.DataManipulation.DataValidator, not adding to appData");
        return null;
    } else {//from   w  w w . ja v a  2  s.c om
        String icon = Base64.getEncoder().encodeToString(iconByte);
        return icon;
    }
}

From source file:org.loklak.susi.SusiInteraction.java

public SusiInteraction react(int maxcount, String client, SusiMind mind, SusiThought observation) {
    this.json.put("client_id", Base64.getEncoder().encodeToString(UTF8.getBytes(client)));
    long query_date = System.currentTimeMillis();
    this.json.put("query_date", AbstractObjectEntry.utcFormatter.print(query_date));

    // compute the mind reaction
    String query = this.json.getString("query");

    List<SusiArgument> dispute = mind.react(query, maxcount, client, observation);
    long answer_date = System.currentTimeMillis();

    // store answer and actions into json
    this.json.put("answer_date", AbstractObjectEntry.utcFormatter.print(answer_date));
    this.json.put("answer_time", answer_date - query_date);
    this.json.put("count", maxcount);
    this.json.put("answers", new JSONArray(dispute.stream().map(argument -> {
        SusiThought answer = argument.mindmeld(true);
        answer.put("actions",
                argument.getActions().stream().map(action -> action.apply(argument, mind, client).toJSONClone())
                        .collect(Collectors.toList()));
        return answer;
    }).collect(Collectors.toList())));

    //System.out.println(this.json);
    return this;
}