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

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

Introduction

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

Prototype

public static String decode(byte[] bytes) 

Source Link

Document

Decode the bytes in UTF-8 form into a String.

Usage

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

public String decrypt(String encryptedText) {
    return Utf8.decode(encryptor.decrypt(Hex.decode(encryptedText)));
}

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

@Override
public AuditEvent getAuditEvent() {

    String name = getAuthentication().getName();

    try {//from w ww .j  av  a  2 s .c  o 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 getToken(String tokenString) {
    final String key = unwrapToken(tokenString);
    if (key.isEmpty()) {
        return null;
    }//from  w ww  .  j  a va  2  s  .c  o m
    byte[] decodedKey = base32.decode(key);
    byte[] currentSignature;
    final long creationTime;
    byte[] random;
    byte[] payload;
    {
        byte[] content;
        {
            ByteBuffer buffer = ByteBuffer.wrap(decodedKey);
            content = restoreArray(buffer);
            currentSignature = restoreArray(buffer);
        }

        ByteBuffer contentBuffer = ByteBuffer.wrap(content);
        creationTime = contentBuffer.getLong();
        random = restoreArray(contentBuffer);
        // we need to skip secret
        restoreArray(contentBuffer);
        payload = restoreArray(contentBuffer);
    }

    final byte[] serverSecret = computeServerSecretApplicableAt(creationTime);

    // Verification
    byte[] expectedSign = sign(contentPack(creationTime, random, serverSecret, payload));
    Assert.isTrue(Arrays.equals(expectedSign, currentSignature), "Key verification failure");

    String[] unpack = unpack(Utf8.decode(payload));
    return new TokenDataImpl(creationTime, TokenUtils.getKeyWithTypeAndToken(TYPE, key), unpack[0], unpack[1]);
}

From source file:org.springframework.security.crypto.scrypt.SCryptPasswordEncoder.java

private String encodePart(byte[] part) {
    return Utf8.decode(Base64.getEncoder().encode(part));
}

From source file:org.springframework.security.ldap.LdapUtils.java

public static String convertPasswordToString(Object passObj) {
    Assert.notNull(passObj, "Password object to convert must not be null");

    if (passObj instanceof byte[]) {
        return Utf8.decode((byte[]) passObj);
    } else if (passObj instanceof String) {
        return (String) passObj;
    } else {//from  ww w  .j  a  v  a2s .  c  o m
        throw new IllegalArgumentException("Password object was not a String or byte array.");
    }
}