Example usage for java.nio.charset StandardCharsets US_ASCII

List of usage examples for java.nio.charset StandardCharsets US_ASCII

Introduction

In this page you can find the example usage for java.nio.charset StandardCharsets US_ASCII.

Prototype

Charset US_ASCII

To view the source code for java.nio.charset StandardCharsets US_ASCII.

Click Source Link

Document

Seven-bit ASCII, also known as ISO646-US, also known as the Basic Latin block of the Unicode character set.

Usage

From source file:com.acciente.oacc.encryptor.jasypt.LegacyJasyptPasswordEncryptor.java

@Override
public String encryptPassword(final char[] password) {
    if (password == null) {
        return null;
    }/*from   w  w w  .j av  a2 s. co m*/

    final byte[] digest = this.digester.digest(getCleanedBytes(password));

    return new String(this.base64.encode(digest), StandardCharsets.US_ASCII);
}

From source file:com.joyent.manta.config.ConfigContextTest.java

public void canValidateContextWithKeyPaths() throws IOException {
    File mantaAuthPrivateKey = File.createTempFile("manta-key", "");
    FileUtils.forceDeleteOnExit(mantaAuthPrivateKey);
    FileUtils.write(mantaAuthPrivateKey, UnitTestConstants.PRIVATE_KEY, StandardCharsets.US_ASCII);

    File encryptionPrivateKey = File.createTempFile("encryption-key", "");
    FileUtils.forceDeleteOnExit(encryptionPrivateKey);
    FileUtils.writeByteArrayToFile(encryptionPrivateKey, keyBytes);

    StandardConfigContext config = new StandardConfigContext();
    config.setMantaURL(DefaultsConfigContext.DEFAULT_MANTA_URL);
    config.setMantaUser("username");
    config.setMantaKeyId(UnitTestConstants.FINGERPRINT);
    config.setMantaKeyPath(mantaAuthPrivateKey.getAbsolutePath());
    config.setClientEncryptionEnabled(true);
    config.setEncryptionKeyId("test-key-1");
    config.setEncryptionAuthenticationMode(EncryptionAuthenticationMode.DEFAULT_MODE);
    config.setPermitUnencryptedDownloads(false);
    config.setEncryptionPrivateKeyPath(encryptionPrivateKey.getAbsolutePath());
    config.setEncryptionAlgorithm(AesGcmCipherDetails.INSTANCE_128_BIT.getCipherId());

    ConfigContext.validate(config);//from  w  w w  .  ja  v  a 2 s . co m
}

From source file:org.graylog2.streams.StreamListFingerprint.java

private String buildFingerprint(List<Stream> streams) {
    final MessageDigest sha1Digest = DigestUtils.getSha1Digest();

    final StringBuilder sb = new StringBuilder();
    for (Stream stream : Ordering.from(getStreamComparator()).sortedCopy(streams)) {
        sb.append(stream.hashCode());//from  www. j a  v  a  2  s  . co m

        for (StreamRule rule : Ordering.from(getStreamRuleComparator()).sortedCopy(stream.getStreamRules())) {
            sb.append(rule.hashCode());
        }
        for (Output output : Ordering.from(getOutputComparator()).sortedCopy(stream.getOutputs())) {
            sb.append(output.hashCode());
        }
    }
    return String.valueOf(Hex.encodeHex(sha1Digest.digest(sb.toString().getBytes(StandardCharsets.US_ASCII))));
}

From source file:org.sonar.scanner.scan.filesystem.InputFileBuilderTest.java

@Test
public void should_detect_charset_from_BOM() {
    File basedir = new File("src/test/resources/org/sonar/scanner/scan/filesystem/");
    when(fs.baseDir()).thenReturn(basedir);
    when(fs.encoding()).thenReturn(StandardCharsets.US_ASCII);
    when(langDetection.language(any(InputFile.class))).thenReturn("java");
    InputFileBuilder builder = new InputFileBuilder("moduleKey", new PathResolver(), langDetection,
            statusDetection, fs, new MapSettings(), new FileMetadata());

    assertThat(createAndComplete(builder, new File(basedir, "without_BOM.txt")).charset())
            .isEqualTo(StandardCharsets.US_ASCII);
    assertThat(createAndComplete(builder, new File(basedir, "UTF-8.txt")).charset())
            .isEqualTo(StandardCharsets.UTF_8);
    assertThat(createAndComplete(builder, new File(basedir, "UTF-16BE.txt")).charset())
            .isEqualTo(StandardCharsets.UTF_16BE);
    assertThat(createAndComplete(builder, new File(basedir, "UTF-16LE.txt")).charset())
            .isEqualTo(StandardCharsets.UTF_16LE);
    assertThat(createAndComplete(builder, new File(basedir, "UTF-32BE.txt")).charset())
            .isEqualTo(InputFileBuilder.UTF_32BE);
    assertThat(createAndComplete(builder, new File(basedir, "UTF-32LE.txt")).charset())
            .isEqualTo(InputFileBuilder.UTF_32LE);

    try {//ww  w .  j a  v  a  2s .  c o  m
        createAndComplete(builder, new File(basedir, "non_existing"));
        Assert.fail();
    } catch (IllegalStateException e) {
        assertThat(e.getMessage())
                .isEqualTo("Unable to read file " + new File(basedir, "non_existing").getAbsolutePath());
        assertThat(e.getCause()).isInstanceOf(FileNotFoundException.class);
    }
}

From source file:org.apache.cloudstack.storage.configdrive.ConfigDriveBuilder.java

/**
 *  Read the content of a {@link File} and convert it to a String in base 64.
 *  We expect the content of the file to be encoded using {@link StandardCharsets#US_ASC}
 *//*  w  w  w . j av  a 2s.  c o  m*/
public static String fileToBase64String(File isoFile) throws IOException {
    byte[] encoded = Base64.encodeBase64(FileUtils.readFileToByteArray(isoFile));
    return new String(encoded, StandardCharsets.US_ASCII);
}

From source file:nl.salp.warcraft4j.dev.casc.model.ListFile.java

public long getHash(String filename) {
    return Optional.ofNullable(filename).filter(StringUtils::isNotEmpty)
            .map(f -> files.getOrDefault(f, ((Supplier<Long>) () -> {
                byte[] data = f.replace('/', '\\').toUpperCase().getBytes(StandardCharsets.US_ASCII);
                long hash = JenkinsHash.hashLittle2(data, data.length);
                files.put(f, hash);//  w w w . ja  v  a2s . co m
                hashes.put(hash, f);
                calculated.add(hash);
                return hash;
            }).get())).orElse(0L);
}

From source file:org.flowable.job.service.impl.history.async.util.AsyncHistoryJsonUtil.java

public static String convertToBase64(VariableInstanceEntity variable) {
    byte[] bytes = variable.getBytes();
    if (bytes != null) {
        return new String(Base64.getEncoder().encode(variable.getBytes()), StandardCharsets.US_ASCII);
    } else {//from  w w  w.ja va2s. co m
        return null;
    }
}

From source file:org.apache.hadoop.hive.druid.security.DruidKerberosUtil.java

/**
 * This method always needs to be called within a doAs block so that the client's TGT credentials
 * can be read from the Subject.//from   ww  w .  j  a  va2s.  c o  m
 *
 * @return Kerberos Challenge String.
 *
 * @throws AuthenticationException on authentication errors.
 */

static String kerberosChallenge(String server) throws AuthenticationException {
    KERBEROS_LOCK.lock();
    try {
        // This Oid for Kerberos GSS-API mechanism.
        Oid mechOid = KerberosUtil.getOidInstance("GSS_KRB5_MECH_OID");
        GSSManager manager = GSSManager.getInstance();
        // GSS name for server
        GSSName serverName = manager.createName("HTTP@" + server, GSSName.NT_HOSTBASED_SERVICE);
        // Create a GSSContext for authentication with the service.
        // We're passing client credentials as null since we want them to be read from the Subject.
        GSSContext gssContext = manager.createContext(serverName.canonicalize(mechOid), mechOid, null,
                GSSContext.DEFAULT_LIFETIME);
        gssContext.requestMutualAuth(true);
        gssContext.requestCredDeleg(true);
        // Establish context
        byte[] inToken = new byte[0];
        byte[] outToken = gssContext.initSecContext(inToken, 0, inToken.length);
        gssContext.dispose();
        // Base64 encoded and stringified token for server
        LOG.debug("Got valid challenge for host {}", serverName);
        return new String(BASE_64_CODEC.encode(outToken), StandardCharsets.US_ASCII);
    } catch (GSSException | IllegalAccessException | NoSuchFieldException | ClassNotFoundException e) {
        throw new AuthenticationException(e);
    } finally {
        KERBEROS_LOCK.unlock();
    }
}

From source file:it.infn.mw.iam.authn.oidc.DefaultOidcTokenRequestor.java

private void basicAuthRequest(RegisteredClient clientConfig, HttpHeaders headers) {

    String auth = clientConfig.getClientId() + ":" + clientConfig.getClientSecret();
    byte[] encodedAuth = org.apache.commons.codec.binary.Base64
            .encodeBase64(auth.getBytes(StandardCharsets.US_ASCII));
    String authHeader = "Basic " + new String(encodedAuth);

    headers.set("Authorization", authHeader);
}

From source file:io.druid.security.kerberos.DruidKerberosUtil.java

/**
 * This method always needs to be called within a doAs block so that the client's TGT credentials
 * can be read from the Subject.//from   www .j a va2s.co m
 *
 * @return Kerberos Challenge String
 *
 * @throws Exception
 */

public static String kerberosChallenge(String server) throws AuthenticationException {
    kerberosLock.lock();
    try {
        // This Oid for Kerberos GSS-API mechanism.
        Oid mechOid = KerberosUtil.getOidInstance("GSS_KRB5_MECH_OID");
        GSSManager manager = GSSManager.getInstance();
        // GSS name for server
        GSSName serverName = manager.createName("HTTP@" + server, GSSName.NT_HOSTBASED_SERVICE);
        // Create a GSSContext for authentication with the service.
        // We're passing client credentials as null since we want them to be read from the Subject.
        GSSContext gssContext = manager.createContext(serverName.canonicalize(mechOid), mechOid, null,
                GSSContext.DEFAULT_LIFETIME);
        gssContext.requestMutualAuth(true);
        gssContext.requestCredDeleg(true);
        // Establish context
        byte[] inToken = new byte[0];
        byte[] outToken = gssContext.initSecContext(inToken, 0, inToken.length);
        gssContext.dispose();
        // Base64 encoded and stringified token for server
        return new String(base64codec.encode(outToken), StandardCharsets.US_ASCII);
    } catch (GSSException | IllegalAccessException | NoSuchFieldException | ClassNotFoundException e) {
        throw new AuthenticationException(e);
    } finally {
        kerberosLock.unlock();
    }
}