Importing JAVA libraries in QT
-
wrote on 12 Mar 2021, 11:35 last edited by
I have the following java implemented for signature generation(private and public keys) and encryption.
How to import java libraries in QT or Is there any libraries in QT which can be used for signature generation and encryption?
can anyone guide me through here!!!import java.security.KeyFactory;
import java.security.Signature;
import java.security.spec.PKCS8EncodedKeySpec;
import java.util.Base64;
public class DigitalSignatureClient {
public static void main(String[] args) throws Exception {
String jsonPayload = "{"Colour": Green,"Quantity": "350","Origin": "India", "cat_ID": "00498D4AC","Member_Id": "XYZ","Availablity": "yes","Business-cat": "Food"}";
String strPrivateKey = "xyz";
String realPK = strPrivateKey.replaceAll(", ", "")byte[] b1 = Base64.getDecoder().decode(realPK); PKCS8EncodedKeySpec spec = new PKCS8EncodedKeySpec(b1); KeyFactory kf = KeyFactory.getInstance("RSA"); Signature privateSignature = Signature.getInstance("SHA256withRSA"); privateSignature.initSign(kf.generatePrivate(spec)); privateSignature.update(jsonPayload.getBytes("UTF-8")); byte[] s = privateSignature.sign(); String base64Signature = Base64.getEncoder().encodeToString(s); System.out.println("Signature=\n" + base64Signature); }
}
Thanks in advance
-
I have the following java implemented for signature generation(private and public keys) and encryption.
How to import java libraries in QT or Is there any libraries in QT which can be used for signature generation and encryption?
can anyone guide me through here!!!import java.security.KeyFactory;
import java.security.Signature;
import java.security.spec.PKCS8EncodedKeySpec;
import java.util.Base64;
public class DigitalSignatureClient {
public static void main(String[] args) throws Exception {
String jsonPayload = "{"Colour": Green,"Quantity": "350","Origin": "India", "cat_ID": "00498D4AC","Member_Id": "XYZ","Availablity": "yes","Business-cat": "Food"}";
String strPrivateKey = "xyz";
String realPK = strPrivateKey.replaceAll(", ", "")byte[] b1 = Base64.getDecoder().decode(realPK); PKCS8EncodedKeySpec spec = new PKCS8EncodedKeySpec(b1); KeyFactory kf = KeyFactory.getInstance("RSA"); Signature privateSignature = Signature.getInstance("SHA256withRSA"); privateSignature.initSign(kf.generatePrivate(spec)); privateSignature.update(jsonPayload.getBytes("UTF-8")); byte[] s = privateSignature.sign(); String base64Signature = Base64.getEncoder().encodeToString(s); System.out.println("Signature=\n" + base64Signature); }
}
Thanks in advance
@cnag said in Importing JAVA libraries in QT:
How to import java libraries in QT
Qt is a C++ framework.
What you want is to know how to execute Java binaries in a C++ application. See https://docs.oracle.com/javase/8/docs/technotes/guides/jni/ -
wrote on 12 Mar 2021, 12:35 last edited by
Hi @jsulm ,
we have decided to move with QT for cross platform signature generation(private and public keys )and encryption, so is there any way this can be implemented in QT framework??
Any specific libraries to provide encryption? -
Hi @jsulm ,
we have decided to move with QT for cross platform signature generation(private and public keys )and encryption, so is there any way this can be implemented in QT framework??
Any specific libraries to provide encryption?@cnag To calculate hashes there is https://doc.qt.io/qt-5/qcryptographichash.html
For encryption there is nothing in Qt, but Qt already uses OpenSSL (which also can be installed using Qt Maintenance Tool) which you can use in your app. -
Hi,
The QCA project might fit your needs.
-
Follow the instructions from the INSTALL file.
-
wrote on 17 Mar 2021, 11:35 last edited by
Hi @SGaist ,
I tried to follow instructions from INSTALL file , unfortunately couldn't import QCA .
am using windows machine and the instructions were given for Linux machine .Is there any alternative to import QCA in windows machine ? -
Citing
INSTALL
:For Unix/Linux/Mac/Windows:
What exactly did you do ?
What failed ? -
wrote on 17 Mar 2021, 13:32 last edited by
well i had to use cmake in order to import QCA in windows and getting an error in configuration process. am not sure whether some changes has to be made in cmake.txt files or install openSSL in order to run it.
-
Without giving more details, it's impossible to give you an answer.
1/11