gpt4 book ai didi

go - Go中字符串的安全比较

转载 作者:IT老高 更新时间:2023-10-28 13:07:00 53 4
gpt4 key购买 nike

Go 中是否有内置的恒定时间字符串比较方法?

我用过 Devise.secure_compare当我在 Ruby 中需要此功能时的方法。

最佳答案

不是字符串,而是 []byte。见 crypto/subtle , 特别是 ConstantTimeCompare :

func ConstantTimeCompare(x, y []byte) int

ConstantTimeCompare returns 1 iff the two equal length slices, x and y, have equal contents. The time taken is a function of the length of the slices and is independent of the contents.

如您所知,您可以轻松地将字符串转换为字节 slice :

var x []byte = []byte("someString")

关于go - Go中字符串的安全比较,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20663468/

53 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com