Example usage for org.springframework.security.crypto.codec Base64 isBase64

List of usage examples for org.springframework.security.crypto.codec Base64 isBase64

Introduction

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

Prototype

public static boolean isBase64(byte[] bytes) 

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  ww.j a va2 s  . com
            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;

}

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

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

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

    return data;

}