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

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

Introduction

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

Prototype

public static byte[] decode(CharSequence s) 

Source Link

Usage

From source file:org.springframework.cloud.config.server.encryption.EncryptionController.java

private String stripFormData(String data, MediaType type, boolean cipher) {

    if (data.endsWith("=") && !type.equals(MediaType.TEXT_PLAIN)) {
        try {/*from w  w  w.  j av  a2  s. c o  m*/
            data = URLDecoder.decode(data, "UTF-8");
            if (cipher) {
                data = data.replace(" ", "+");
            }
        } catch (UnsupportedEncodingException e) {
            // Really?
        }
        String candidate = data.substring(0, data.length() - 1);
        if (cipher) {
            if (data.endsWith("=")) {
                if (data.length() / 2 != (data.length() + 1) / 2) {
                    try {
                        Hex.decode(candidate);
                        return candidate;
                    } catch (IllegalArgumentException e) {
                        if (Base64.isBase64(data.getBytes())) {
                            return data;
                        }
                    }
                }
            }
            return data;
        }
        // User posted data with content type form but meant it to be text/plain
        data = candidate;
    }

    return data;

}