dsepcxw181184853 2019-04-01 20:51
浏览 460

使用Golang中的任何类型的类型加密(例如AES等)对JWT进行加密和解密

I am searching for a library in Go that can give to me the capability of crypting for send and decrypting for reading a JWT that I send when a user is logged in my api rest made in Golang.

I have seen a lot of examples with AES, but I have a lot of issues trying to encrypt in AES a JWT because signs like "." or "-" give me problems.

I know that I must use a 32 bytes key, that I can change the base to 64. But only using the most simple example, making a simple hash, using the cipher, I have always the same error at crypting/decrypting.

For instance :

crypto/aes: invalid key size X

I use the same code like this Stack Overflow answer :AES Encryption Golang and Python

I have already my token signed, I want to add a new level of security after signing.

claims := Claim{
    User: user,
    StandardClaims: djwt.StandardClaims{
        ExpiresAt: time.Now().Add(time.Hour * 1).Unix(),
        Issuer: "App Timer",
    },
}

token := djwt.NewWithClaims(djwt.SigningMethodRS256, claims)
result, err := token.SignedString(privateKey)

if err != nil {
    log.Fatal("TokenSingingError")
}
  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 素材场景中光线烘焙后灯光失效
    • ¥15 请教一下各位,为什么我这个没有实现模拟点击
    • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
    • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
    • ¥20 有关区间dp的问题求解
    • ¥15 多电路系统共用电源的串扰问题
    • ¥15 slam rangenet++配置
    • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
    • ¥15 ubuntu子系统密码忘记
    • ¥15 保护模式-系统加载-段寄存器