相关疑难解决方法(0)

将UUID存储为base64字符串

我一直在尝试使用UUID作为数据库密钥.我想尽可能占用最少的字节数,同时仍然保持UUID表示可读.

我认为我已经使用base64将它降低到22个字节,并删除了一些似乎没有必要为我的目的存储的尾随"==".这种方法有什么缺陷吗?

基本上我的测试代码会进行一系列转换,以将UUID降低到22字节的字符串,然后将其转换回UUID.

import java.io.IOException;
import java.util.UUID;

public class UUIDTest {

    public static void main(String[] args){
        UUID uuid = UUID.randomUUID();
        System.out.println("UUID String: " + uuid.toString());
        System.out.println("Number of Bytes: " + uuid.toString().getBytes().length);
        System.out.println();

        byte[] uuidArr = asByteArray(uuid);
        System.out.print("UUID Byte Array: ");
        for(byte b: uuidArr){
            System.out.print(b +" ");
        }
        System.out.println();
        System.out.println("Number of Bytes: " + uuidArr.length);
        System.out.println();


        try {
            // Convert a byte array to base64 string
            String s = new sun.misc.BASE64Encoder().encode(uuidArr);
            System.out.println("UUID Base64 String: " +s);
            System.out.println("Number of Bytes: " + …
Run Code Online (Sandbox Code Playgroud)

java sql uuid base64 bytearray

70
推荐指数
5
解决办法
7万
查看次数

将UUID转换为短代码是否安全?(仅使用前8个字符)

我们在数据库中使用UUID作为主键(由php生成,存储在mysql中).问题在于,当有人想要编辑某些内容或查看他们的个人资料时,他们会在网址的末尾有这个巨大的,可怕的,丑陋的uuid字符串.(编辑?ID = .....)

如果我们只使用前8个字符,在第一个连字符之前的所有内容,它是否安全(读:仍然是唯一的)?

如果它不安全,是否有某种方法可以将其转换为更短的内容,以便在url中使用,可以将其转换回十六进制用作查找?我知道我可以对它进行base64编码,将其降低到22个字符,但还有更短的东西吗?

编辑我已经阅读了这个问题,它说使用base64.再一次,什么更短?

php algorithm uuid base64

6
推荐指数
2
解决办法
5492
查看次数

标签 统计

base64 ×2

uuid ×2

algorithm ×1

bytearray ×1

java ×1

php ×1

sql ×1