2 回答
TA贡献1824条经验 获得超6个赞
如果发生这种情况,请遵循 FIPS186-4 第 4.6 节和第 4.7 节
hashed := []byte{1}
pemData, _ := ioutil.ReadFile("config/secure/private.key")
p, err := ssh.ParseRawPrivateKey(pemData)
pp, ok := p.(*dsa.PrivateKey)
h := sha256.New()
h.Write(hashed)
hashed := h.Sum(nil)
if pp.Q.BitLen()/8 < len(hashed) {
hashed = hashed[0 : pp.Q.BitLen()/8]
}
r, s, _ := dsa.Sign(rand.Reader, pp, hashed)
var ss dsaSignature
ss.S = s
ss.R = r
hashed, _ = asn1.Marshal(ss)
TA贡献1963条经验 获得超6个赞
我在爪哇中发现
package sun.security.provider;
private BigInteger generateS(BigInteger var1, BigInteger var2, BigInteger var3, BigInteger var4) throws SignatureException {
byte[] var5;
try {
var5 = this.md.digest();
} catch (RuntimeException var9) {
throw new SignatureException(var9.getMessage());
}
// this line split the hash256 redsult
int var6 = var2.bitLength() / 8;
if (var6 < var5.length) {
var5 = Arrays.copyOfRange(var5, 0, var6);
}
BigInteger var7 = new BigInteger(1, var5);
BigInteger var8 = var4.modInverse(var2);
return var1.multiply(var3).add(var7).multiply(var8).mod(var2);
}
你可以在戈朗使用
hashed := []byte{1}
sha256 := sha2562.New()
sha256.Write(hashed)
hashed = sha256.Sum(nil)
// you must split it
hashed = hashed[0:20]
原因是sha256结果在java中分裂,但glang没有分裂
- 2 回答
- 0 关注
- 112 浏览
添加回答
举报