Skip to Main Content

Java Security

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

error decoding signature bytes

843810Jun 13 2002 — edited Jun 13 2002
Hi

I am getting
"Caught exception java.security.SignatureException: error decoding signature bytes."
when I call sig.verify(sigToVerify);
I tried URL encoding the signature but it did not help. I am using X.509 V3 certificate.The signature algorithm is DSA. I am using Boucycastle 1.14B. I am really frustrated with this problem & any tips will be highly appreciated.

Signature
"MIIBlgYJKoZIhvcNAQcCoIIBhzCCAYMCAQExCzAJBgUrDgMCGgUAMAsGCSqGSIb3DQEHATGCAWIwggFeAgEBMBMwDjEMMAoGA1UEAxMDSUQzAgEAMAkGBSsOAwIaBQCgXTAYBgkqhkiG9w0BCQMxCwYJKoZIhvcNAQcBMBwGCSqGSIb3DQEJBTEPFw0wMjA2MTMyMDIxNDBaMCMGCSqGSIb3DQEJBDEWBBQq44TQMvt2AqFTbn2GGObmPjDQRjCBpwYFKw4DAhswgZ0CQQEkJRHP%2BmN7d8miwTMN55CUSmo3TO8WGCxgY61TX5k%2B7NU4XPf1TULjw3GobwaJX13kquPhfVXk%2BgVy46n4Iw3hAhUBSe%2FQF4BUj%2BpJOF9ROBM4u%2BFEWA8CQQD4mSJbrABjTUWrlnAte8pS22Tq4%2FFPO7jHSqjijUHfXKTrHL1OEqV3SVWcFy5j%2FcqBgX%2Fzm8Q12PFp%2FPjOhh%2BnBDAwLgIVAPjFHQubiVnMECfOV3o%2BAwPdtYHiAhUBR23LzQCE7egauSPa1dAFZbNOwH4%3D"

data "C1C573A5CBF56CDE46B8C42535B5DE00FCrCN%3DID320020613210142"
import java.io.InputStream;
import java.io.FileInputStream;
import java.io.BufferedInputStream;
import java.io.File;
import java.util.Collection;                            
import java.util.Iterator;
import java.util.LinkedList;

import  org.bouncycastle.asn1.x509.X509CertificateStructure;
import org.bouncycastle.jce.cert.CertificateFactory;
import java.security.cert.X509Certificate;
import java.security.PublicKey;
import java.security.Signature;

public class VerSignUsing14 {
    public static void main(String[] args) {

        /* Verify a DSA signature */

        if (args.length != 3) {
            System.out.println("Usage: VerSig publickeyfile signaturefile datafile");
        }
        else try{

            File certfile = new File(args[0]);
            FileInputStream fis = new FileInputStream(certfile);
            CertificateFactory cf= CertificateFactory.getInstance("X.509","BC");

            // read certificates into a list
            LinkedList list=new LinkedList();
            X509Certificate cert = null;
            while (fis.available() > 0) {
                cert=(X509Certificate)cf.generateCertificate(fis);
                list.add(cert);
            }
            fis.close();
            PublicKey pubKey = null;
            if (cert != null)
                pubKey = cert.getPublicKey();
            // create a Signature object and initialize it with the public key
            String pub_algorithm = pubKey.getAlgorithm();
            String format = pubKey.getFormat();
            Signature sig = Signature.getInstance(pub_algorithm,"BC");
            //sig.initVerify(pubKey);
            sig.initVerify(cert);

            // Update and verify the data

            FileInputStream datafis = new FileInputStream(args[2]);
            BufferedInputStream bufin = new BufferedInputStream(datafis);

            byte[] buffer = new byte[1024];
            int len;
            while (bufin.available() != 0) {
                len = bufin.read(buffer);
                sig.update(buffer, 0, len);
            };

            bufin.close();
            //input the signature bytes
            FileInputStream sigfis = new FileInputStream(args[1]);
            byte[] sigToVerify = new byte[sigfis.available()];
            sigfis.read(sigToVerify );
            sigfis.close();
            boolean verifies = sig.verify(sigToVerify);
            System.out.println("signature verifies: " + verifies);

        } catch (Exception e) {
            System.err.println("Caught exception " + e.toString());
        };
    }
}
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Jul 11 2002
Added on Jun 13 2002
1 comment
1,137 views