android verify signature of file with .der public key

'JcaVerify.java - Signature Verification Sample Program' tutorial was cited in a StackOverflow forum post in 2012.

The JcaVerify.java - Signature Verification Sample Program tutorial was cited in a StackOverflow forum post in 2012.

Subject: android verify signature of file with .der public key
Date: Dec. 10, 2012
Author: Josh
Source: http://stackoverflow.com/questions/13807267
   /android-verify-signature-of-file-with-der-public-key


I'm trying to verify the signature of a file. I followed these 
instruction to generate a certificate:

// generate a private key with size of 2048 bits
openssl genrsa -out private_key.pem 2048

// derive a public key from the above private key
openssl rsa -in private_key.pem -out public_key.pem -outform PEM 
   -pubout

// iOS will not import PEM encoded data so it needs to be converted
// to DER encoded data
openssl rsa -pubin -inform PEM -outform DER -in public_key.pem 
   -out public_key.der

// generate a self-signed certificate for testing
openssl req -new -x509 -key private_key.pem -out test_cert.pem 
   -days 1095

// show the content of the original certificate
openssl x509 -in test_cert.pem -text -noout
// convert the certificate to DER format
openssl x509 -in test_cert.pem -outform der -out test_cert.der
// show the content of the new certificate
openssl x509 -in test_cert.der -inform der -text -noout

I used the example at this link to hash some data and verify that 
everything was all good (I did steps 2 - 5).

Now I'm trying to put the .der file, the signature file, and the data 
file into an Android application and basically verify it's all good 
again. I'm not getting any errors, but I'm not getting false.. Below
 is the code I've written:

import android.app.Activity;
import android.os.Bundle;
import android.os.Environment;
import android.util.Base64;
import android.util.Log;
import android.widget.TextView;

import java.io.*;
import java.security.*;
import java.security.cert.CertificateFactory;
import java.security.cert.Certificate;

// Most of the below is taken from:
// http://www.herongyang.com/JDK
// /Digital-Signature-JcaVerify-Signature-Verification-Program.html
public class MyActivity extends Activity {

String input = Environment.getExternalStorageDirectory() + "/data.txt";
String signFile = Environment.getExternalStorageDirectory() + "/signature";
String signAlgo = "SHA1withRSA";
int keyFile = R.raw.test_cert_josh;
String TAG = "VERIFY";

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);

    TextView textView = (TextView) findViewById(R.id.textView);

    try {
        PublicKey pubKey = readPublicKey(keyFile);
        byte[] sign = readSignature(signFile);
        textView.setText(verify(input, signAlgo, sign, pubKey) + "");
    } catch (Exception e) {
        e.printStackTrace();
    }
}
...

Table of Contents

 About This Book

 Reference Citations in 2016

 Reference Citations in 2015

 Reference Citations in 2014

 Reference Citations in 2013

Reference Citations in 2012

 bikin website dalam bahasa cina dengan php

 72 sekunde kao 72 godine

 nsIConverterOutputStream handling GB2312 characters

 AbstractMethodError while calling PreparedStatement.setBinaryStream()

 how to invoke web service without generating a client

 Sample program to test SSL Connection with certicates

 How to know KeyManager given a keystore

 once again: classpath and ojdbc14.jar

 12c... webtier up, Oracle managment server down

 Problems with class not found exception

 Spring Projects > Roo > Issue with Chinese characters

 Monkey Programming/Unsigned Shift Right

 Unable to get issuer certificate

 How to convert keystore (from native android project) to .p12 to use with AIR project?

 Installing JDBC drivers ojdbc14.jar

 Quickly view the threads of your blocked Ruby application with JStack

android verify signature of file with .der public key

 Unable to install updates KB2770917 and KB2779768

 Reference Citations in 2011

 Reference Citations in 2010

 Reference Citations in 2009

 Reference Citations in 2008

 Reference Citations in 2007

 Reference Citations in 2006

 Reference Citations in 2005

 Reference Citations in 2004

 Reference Citations in 2003

 PDF Printing Version