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 TI的insta-spin例程
    • ¥15 完成下列问题完成下列问题
    • ¥15 C#算法问题, 不知道怎么处理这个数据的转换
    • ¥15 YoloV5 第三方库的版本对照问题
    • ¥15 请完成下列相关问题!
    • ¥15 drone 推送镜像时候 purge: true 推送完毕后没有删除对应的镜像,手动拷贝到服务器执行结果正确在样才能让指令自动执行成功删除对应镜像,如何解决?
    • ¥15 求daily translation(DT)偏差订正方法的代码
    • ¥15 js调用html页面需要隐藏某个按钮
    • ¥15 ads仿真结果在圆图上是怎么读数的
    • ¥20 Cotex M3的调试和程序执行方式是什么样的?