blob: 1b83d55e0dfe07637f8c4a06d039ac11472259e4 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
|
package org.spongycastle.jcajce.provider.asymmetric.dstu;
import java.io.IOException;
import java.security.SignatureException;
import org.spongycastle.asn1.ASN1OctetString;
import org.spongycastle.asn1.DEROctetString;
public class SignatureSpiLe
extends SignatureSpi
{
void reverseBytes(byte[] bytes)
{
byte tmp;
for (int i = 0; i < bytes.length / 2; i++)
{
tmp = bytes[i];
bytes[i] = bytes[bytes.length - 1 - i];
bytes[bytes.length - 1 - i] = tmp;
}
}
protected byte[] engineSign()
throws SignatureException
{
byte[] signature = ASN1OctetString.getInstance(super.engineSign()).getOctets();
reverseBytes(signature);
try
{
return (new DEROctetString(signature)).getEncoded();
}
catch (Exception e)
{
throw new SignatureException(e.toString());
}
}
protected boolean engineVerify(
byte[] sigBytes)
throws SignatureException
{
byte[] bytes = null;
try
{
bytes = ((ASN1OctetString)ASN1OctetString.fromByteArray(sigBytes)).getOctets();
}
catch (IOException e)
{
throw new SignatureException("error decoding signature bytes.");
}
reverseBytes(bytes);
try
{
return super.engineVerify((new DEROctetString(bytes)).getEncoded());
}
catch (SignatureException e)
{
throw e;
}
catch (Exception e)
{
throw new SignatureException(e.toString());
}
}
}
|