MySQL中的url安全base64
MySQL的TO_BASE64 URL安全吗?使用java,我可以编写以下代码:MySQL中的url安全base64,mysql,base64,message-digest,Mysql,Base64,Message Digest,MySQL的TO_BASE64 URL安全吗?使用java,我可以编写以下代码: 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 b
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);
}
}
在阅读了这些文档之后,我最终做了以下工作: 将“+”替换为“-” 将“/”替换为“\u1” 删除尾随“=”
SELECT TRIM(TRAILING '=' FROM REPLACE(REPLACE(CONCAT('SHA-1', TO_BASE64('SomeText')), '+', '-'), '/', '_')) AS input;