When you cut&pasted your code, you didn't edit correctly. It still reads the data into buffer
, but it doesn't use that data, instead it uses buffer2
(which is all zeros):
byte[] buffer2 = new byte[1024];
int len2;
while (bufin2.available() != 0) {
len2 = bufin2.read(buffer);
sig.update(buffer2, 0, len2);
};
Also, in general available()
can return 0 even when there is more data in the file, so this isn't reliable; the method you used in the signing part, while( (len=inputstream.read(buffer))>=0 )
is much better.
And in case you aren't aware, 1024-bit DSA, although not actually broken (yet), is no longer considered safe and no longer allowed for use where security is needed, especially not in conjunction with SHA-256. Java crypto since j8 in 2014 supports 2048-bit and 3072-bit DSA with SHA-2 as per FIPS 186-3.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…