Example usage for org.springframework.security.crypto.codec Utf8 encode

List of usage examples for org.springframework.security.crypto.codec Utf8 encode

Introduction

In this page you can find the example usage for org.springframework.security.crypto.codec Utf8 encode.

Prototype

public static byte[] encode(CharSequence string) 

Source Link

Document

Get the bytes of the String in UTF-8 encoded form.

Usage

From source file:org.matrix.security.crypto.encrypt.HexEncodingTextEncryptor.java

public String encrypt(String text) {
    return new String(Hex.encode(encryptor.encrypt(Utf8.encode(text))));
}

From source file:it.smartcommunitylab.aac.oauth.AACOAuth2Utils.java

private static String getS256CodeChallenge(String codeVerifier) {
    MessageDigest md;//w w w .j a v a  2s .  c  o m
    try {
        md = MessageDigest.getInstance("SHA-256");
    } catch (NoSuchAlgorithmException e) {
        throw new IllegalArgumentException("No such algorithm [SHA-256]");
    }
    byte[] sha256 = md.digest(Utf8.encode(codeVerifier));
    String codeChallenge = Base64.encodeBase64URLSafeString(sha256);
    return codeChallenge;
}

From source file:org.cloudfoundry.identity.uaa.authentication.event.UserNotFoundEvent.java

@Override
public AuditEvent getAuditEvent() {

    String name = getAuthentication().getName();

    try {/*from   w ww  . ja va 2  s  .  co m*/
        // Store hash of name, to conceal accidental entry of sensitive info (e.g. password)
        name = Utf8.decode(Base64.encode(MessageDigest.getInstance("SHA-1").digest(Utf8.encode(name))));
    } catch (NoSuchAlgorithmException shouldNeverHappen) {
        name = "NOSHA";
    }

    return createAuditRecord(name, AuditEventType.UserNotFound, getOrigin(getAuthenticationDetails()), "");

}

From source file:com.codeabovelab.dm.common.security.token.SignedTokenServiceBackend.java

@Override
public TokenData createToken(TokenConfiguration config) {
    final long creationTime = System.currentTimeMillis();

    byte[] serverSecret = computeServerSecretApplicableAt(creationTime);
    byte[] content = contentPack(creationTime, generateRandom(), serverSecret,
            Utf8.encode(pack(config.getUserName(), config.getDeviceHash())));

    byte[] sign = sign(content);
    ByteBuffer buffer = ByteBuffer.allocate(1 + sign.length + 1 + content.length);
    store(buffer, content);//from   w  w  w . j  av a  2  s  .com
    store(buffer, sign);
    String key = base32.encodeAsString(buffer.array());

    return new TokenDataImpl(creationTime, TokenUtils.getKeyWithTypeAndToken(TYPE, key), config.getUserName(),
            config.getDeviceHash());
}

From source file:com.springsource.greenhouse.account.GreenhousePasswordEncoder.java

/**
 * Creates a fully customized standard password encoder.
 *//* w  w  w  .  java  2  s.c o  m*/
public GreenhousePasswordEncoder(String algorithm, String provider, String secret) {
    this.digester = new Digester(algorithm, provider);
    this.secret = Utf8.encode(secret);
    this.saltGenerator = KeyGenerators.secureRandom();
}

From source file:org.matrix.security.crypto.password.StandardPasswordEncoder.java

private StandardPasswordEncoder(String algorithm, CharSequence secret) {
    this.digester = new Digester(algorithm, DEFAULT_ITERATIONS);
    this.secret = Utf8.encode(secret);
    this.saltGenerator = KeyGenerators.secureRandom();
}

From source file:com.springsource.greenhouse.account.GreenhousePasswordEncoder.java

private byte[] digest(CharSequence rawPassword, byte[] salt) {
    byte[] digest = digester.digest(concatenate(salt, secret, Utf8.encode(rawPassword)));
    return concatenate(salt, digest);
}

From source file:org.cloudfoundry.identity.uaa.authentication.RubyUserTokenTests.java

public String encode() {
    RubyString name = RubyString.newString(Ruby.getGlobalRuntime(), Utf8.encode(username));
    RubyFixnum valid = RubyFixnum.newFixnum(Ruby.getGlobalRuntime(), validUntil);
    RubyString sig = RubyString.newString(Ruby.getGlobalRuntime(), signature);

    RubyArray array = RubyArray.newArrayLight(Ruby.getGlobalRuntime(), name, valid, sig);

    ByteArrayOutputStream baos = new ByteArrayOutputStream();

    try {//from w  w w . j a v  a  2s. c o  m
        MarshalStream ms = new MarshalStream(Ruby.getGlobalRuntime(), baos, -1);
        ms.dumpObject(array);
    } catch (IOException e) {
        throw new RuntimeException(e);
    }

    byte[] bytes = baos.toByteArray();

    //      HexDumpEncoder enc = new HexDumpEncoder();
    //      System.out.println("Marshalled bytes: \n" + enc.encode(bytes));

    return new String(Hex.encode(bytes));
}

From source file:org.cloudfoundry.identity.uaa.authentication.RubyUserTokenTests.java

private static byte[] sign(String username, long validUntil, SecretKey key) {
    Mac mac;/*ww w.  j  av  a 2 s . c o m*/
    try {
        mac = Mac.getInstance("HMACSHA1");
        mac.init(key);
    } catch (GeneralSecurityException e) {
        throw new RuntimeException("Failed to create and initialize MAC: ", e);
    }

    byte[] bytesToSign = Utf8.encode(username + validUntil);
    //      HexDumpEncoder enc = new HexDumpEncoder();
    //      System.out.println("Signing bytes: \n" + enc.encode(bytesToSign));
    byte[] sig = mac.doFinal(bytesToSign);
    //      System.out.println("Signature is: \n" + enc.encode(sig));
    return sig;
}

From source file:com.codeabovelab.dm.common.security.token.SignedTokenServiceBackend.java

private byte[] computeServerSecretApplicableAt(long time) {
    return Utf8.encode(serverSecret + ":" + (time % serverInteger));
}