step1: D:\workspace\DsaDemo\app\src\main\java\com\mondor\dsademo\MainActivity.java
package com.mondor.dsademo;
import androidx.appcompat.app.AppCompatActivity;
import java.math.BigInteger;
import android.os.Bundle;
import android.util.Base64;
import android.util.Log;
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
String message = "Hi I think I have an A";
String message2 = "Hi I think I have an A";
Session session = Session.getInstance(true);
Pair<BigInteger, BigInteger> privateKeys = session.getPrivateKey();
Pair<BigInteger, BigInteger> sign = DSA.sign(true, message,
session.getGlobalKeyG(), session.getGlobalKeyP(),
session.getGlobalKeyQ(), privateKeys.getFirst());
boolean isPass = DSA.verify(true, message2, sign.getFirst(),
sign.getSecond(), session.getGlobalKeyG(),
session.getGlobalKeyP(), session.getGlobalKeyQ(),
privateKeys.getSecond());
session.destroy();
}
}
step2: D:\workspace\DsaDemo\app\src\main\java\com\mondor\dsademo\DSA.java
package com.mondor.dsademo;
import java.math.BigInteger;
import java.security.MessageDigest;
import java.security.SecureRandom;
/**
* @author robertomm
*
*/
public class DSA {
/*
* Static methods -> (M,r,s) sign(M, claves) Boolean verify(M, r, s)
*/
private static boolean debug;
/**
* Method to create the signature
*
* @param deb
* , boolean for activate the debug mode
* @param message
* , string to make the signature
* @param publcG
* , the global public g key
* @param publicP
* , the global public p key
* @param publicQ
* , the global public q key
* @param privateX
* , the personal private x key
* @return Pair<String, Pair<BigInteger, BigInteger>>, Pair of the message
* and another Pair with (r,s)
*/
public static Pair<BigInteger, BigInteger> sign(boolean deb,
String message, BigInteger publcG, BigInteger publicP,
BigInteger publicQ, BigInteger privateX) {
debug = deb;
debugMode("=== CREATING SIGNATURE ===", true);
// K
debugMode("Creating auxiliar variable K .......... ", false);
BigInteger k = new BigInteger(publicQ.bitLength