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:io.undertow.server.handlers.proxy.mod_cluster.MCMPTestClient.java

static HttpEntity createEntity(final List<NameValuePair> pairs) throws UnsupportedEncodingException {
    return new UrlEncodedFormEntity(pairs, StandardCharsets.US_ASCII);
}

From source file:org.kitodo.production.ldap.LdapUser.java

/**
 * Creates the LM Hash of the user's password.
 *
 * @param password/*w  w  w .  j  a va2 s.c  o  m*/
 *            The password.
 * @return The LM Hash of the given password, used in the calculation of the LM
 *         Response.
 */
public static byte[] lmHash(String password) throws BadPaddingException, NoSuchAlgorithmException,
        NoSuchPaddingException, InvalidKeyException, IllegalBlockSizeException {

    byte[] oemPassword = password.toUpperCase().getBytes(StandardCharsets.US_ASCII);
    int length = Math.min(oemPassword.length, 14);
    byte[] keyBytes = new byte[14];
    System.arraycopy(oemPassword, 0, keyBytes, 0, length);
    Key lowKey = createDESKey(keyBytes, 0);
    Key highKey = createDESKey(keyBytes, 7);
    byte[] magicConstant = "KGS!@#$%".getBytes(StandardCharsets.US_ASCII);
    Cipher des = Cipher.getInstance("DES/ECB/NoPadding");
    des.init(Cipher.ENCRYPT_MODE, lowKey);
    byte[] lowHash = des.doFinal(magicConstant);
    des.init(Cipher.ENCRYPT_MODE, highKey);
    byte[] highHash = des.doFinal(magicConstant);
    byte[] lmHash = new byte[16];
    System.arraycopy(lowHash, 0, lmHash, 0, 8);
    System.arraycopy(highHash, 0, lmHash, 8, 8);
    return lmHash;
}

From source file:org.asynchttpclient.ntlm.NtlmTest.java

@Test
public void testGenerateType3Msg() throws IOException {
    ByteArrayOutputStream buf = new ByteArrayOutputStream();
    buf.write("NTLMSSP".getBytes(StandardCharsets.US_ASCII));
    buf.write(0);/*from   w  w  w . ja v  a  2s .c o  m*/
    // type 2 indicator
    buf.write(2);
    buf.write(0);
    buf.write(0);
    buf.write(0);

    buf.write(longToBytes(0L)); // we want to write a Long

    // flags
    buf.write(1);// unicode support indicator
    buf.write(0);
    buf.write(0);
    buf.write(0);

    buf.write(longToBytes(1L));// challenge
    NtlmEngine engine = new NtlmEngine();
    String type3Msg = engine.generateType3Msg("username", "password", "localhost", "workstation",
            Base64.encode(buf.toByteArray()));
    buf.close();
    assertEquals(type3Msg,
            "TlRMTVNTUAADAAAAGAAYAEgAAAAYABgAYAAAABIAEgB4AAAAEAAQAIoAAAAWABYAmgAAAAAAAACwAAAAAQAAAgUBKAoAAAAP1g6lqqN1HZ0wSSxeQ5riQkyh7/UexwVlCPQm0SHU2vsDQm2wM6NbT2zPonPzLJL0TABPAEMAQQBMAEgATwBTAFQAdQBzAGUAcgBuAGEAbQBlAFcATwBSAEsAUwBUAEEAVABJAE8ATgA=",
            "Incorrect type3 message generated");
}

From source file:org.apache.nifi.processors.standard.util.crypto.OpenSSLPKCS5CipherProvider.java

/**
 * Returns the salt provided as part of the cipher stream, or throws an exception if one cannot be detected.
 *
 * @param in the cipher InputStream/*ww w .  j a  va2s .  c om*/
 * @return the salt
 */
@Override
public byte[] readSalt(InputStream in) throws IOException {
    if (in == null) {
        throw new IllegalArgumentException("Cannot read salt from null InputStream");
    }

    // The header and salt format is "Salted__salt x8b" in ASCII
    byte[] salt = new byte[DEFAULT_SALT_LENGTH];

    // Try to read the header and salt from the input
    byte[] header = new byte[OPENSSL_EVP_HEADER_SIZE];

    // Mark the stream in case there is no salt
    in.mark(OPENSSL_EVP_HEADER_SIZE + 1);
    StreamUtils.fillBuffer(in, header);

    final byte[] headerMarkerBytes = OPENSSL_EVP_HEADER_MARKER.getBytes(StandardCharsets.US_ASCII);

    if (!Arrays.equals(headerMarkerBytes, header)) {
        // No salt present
        salt = new byte[0];
        // Reset the stream because we skipped 8 bytes of cipher text
        in.reset();
    }

    StreamUtils.fillBuffer(in, salt);
    return salt;
}

From source file:org.polymap.p4.data.importer.prompts.CharsetPrompt.java

private void initCharsets() {
    charsets = new TreeMap<String, Charset>();

    for (Charset charset : Charset.availableCharsets().values()) {
        charsets.put(displayName(charset), charset);
    }//w  w w .j  a  v a2 s . co m

    displayNames = new ListOrderedSet<String>();
    // add all defaults on top
    displayNames.add(displayName(StandardCharsets.ISO_8859_1));
    displayNames.add(displayName(StandardCharsets.US_ASCII));
    displayNames.add(displayName(StandardCharsets.UTF_8));
    displayNames.add(displayName(StandardCharsets.UTF_16));
    displayNames.add(displayName(StandardCharsets.UTF_16BE));
    displayNames.add(displayName(StandardCharsets.UTF_16LE));

    // a separator
    charsets.put(SEPARATOR, selection);
    displayNames.add(SEPARATOR);

    // add the rest
    for (String displayName : charsets.keySet()) {
        displayNames.add(displayName);
    }
}

From source file:jenkins.security.apitoken.ApiTokenStore.java

private @Nonnull byte[] plainSecretToHashBytes(@Nonnull String secretValueInPlainText) {
    // ascii is sufficient for hex-format
    return hashedBytes(secretValueInPlainText.getBytes(StandardCharsets.US_ASCII));
}

From source file:org.apache.hc.client5.http.impl.auth.NTLMEngineImpl.java

private static byte[] getNullTerminatedAsciiString(final String source) {
    final byte[] bytesWithoutNull = source.getBytes(StandardCharsets.US_ASCII);
    final byte[] target = new byte[bytesWithoutNull.length + 1];
    System.arraycopy(bytesWithoutNull, 0, target, 0, bytesWithoutNull.length);
    target[bytesWithoutNull.length] = (byte) 0x00;
    return target;
}

From source file:patientlinkage.Util.Util.java

public static boolean[][][] readAndEncode(String FileName, int[][] lens) {
    ArrayList<boolean[][]> retArrList = new ArrayList<>();
    int properties_num = lens[0].length;
    Soundex sdx = new Soundex();

    try (CSVReader reader = new CSVReader(new FileReader(FileName))) {
        String[] strs;//ww w .java  2 s  .  c o m
        reader.readNext();
        while ((strs = reader.readNext()) != null) {

            String[] coms_strs = new String[lens.length];
            Arrays.fill(coms_strs, "");
            for (int i = 0; i < properties_num; i++) {
                String temp = strs[i].replace("-", "").toLowerCase();
                for (int j = 0; j < coms_strs.length; j++) {
                    if (lens[j][i] > 65536) {
                        coms_strs[j] += sdx.soundex(temp);
                    } else {
                        coms_strs[j] += resizeString(temp, lens[j][i]);
                    }
                }
            }
            boolean[][] bool_arr = new boolean[coms_strs.length][];
            for (int j = 0; j < coms_strs.length; j++) {
                bool_arr[j] = bytes2boolean(coms_strs[j].getBytes(StandardCharsets.US_ASCII));
            }
            retArrList.add(bool_arr);
        }
    } catch (FileNotFoundException ex) {
        Logger.getLogger(PatientLinkageGadget.class.getName()).log(Level.SEVERE, null, ex);
    } catch (IOException ex) {
        Logger.getLogger(PatientLinkageGadget.class.getName()).log(Level.SEVERE, null, ex);
    }

    boolean[][][] bool_ret = new boolean[retArrList.size()][][];
    for (int i = 0; i < bool_ret.length; i++) {
        bool_ret[i] = retArrList.get(i);
    }

    return bool_ret;
}

From source file:de.undercouch.actson.JsonParserTest.java

/**
 * Test if a JSON text containing utf8 characters cannot be parsed
 * if the parser uses ASCII encoding//w  ww.  j  a v a2 s  .com
 */
@Test
public void utf8Fail() {
    byte[] json = "{\"name\": \"Bj\u0153rn\"}".getBytes(StandardCharsets.UTF_8);
    parseFail(json, new JsonParser(StandardCharsets.US_ASCII));
}

From source file:io.undertow.server.handlers.sse.ServerSentEventTestCase.java

private void assertData(InputStream stream, String data) throws IOException {
    byte[] d = data.getBytes(StandardCharsets.US_ASCII);
    int index = 0;
    byte[] buf = new byte[100];
    while (index < d.length) {
        int r = stream.read(buf);
        if (r == -1) {
            Assert.fail("unexpected end of stream at index " + index);
        }//from w  w  w.  ja  v a2  s .c o  m
        int rem = d.length - index;
        if (r > rem) {
            Assert.fail("Read too much data index: " + index + " expected: " + data + " read: "
                    + new String(buf, 0, r));
        }
        for (int i = 0; i < r; ++i) {
            Assert.assertEquals("Comparison failed " + "index: " + index + " expected: " + data + " read: "
                    + new String(buf, 0, r), d[index++], buf[i]);
        }
    }
}