문제

Is MySQL's TO_BASE64 URL safe? Using java, I can write the following code:

import org.apache.commons.codec.binary.Base64;

public class Main {

    public static void main(String[] args) {
        String text = "SomeText";
        byte[] input = text.getBytes();
        // url safe base64
        // How do I do this in MySQL?
        // I tried mysql> SELECT TO_BASE64('SomeText'); but it does not seem to return url safe output
        Base64 base64 = new Base64(-1, null, true);
        input = base64.encode(input);
    }
}
도움이 되었습니까?

해결책

After reading the docs, this is what I ended up doing:

Replace ‘+’ with '-'

Replace ‘/‘ with '_'

Remove trailing '='

SELECT TRIM(TRAILING '=' FROM REPLACE(REPLACE(CONCAT('SHA-1', TO_BASE64('SomeText')), '+', '-'), '/', '_')) AS input;
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top