1

I am using QR code scanning, and search something that I don't find anywhere. I would like to scan a QR code, which scan a private key and it return me a public key.

How is it feasible?

Abhinav Gupta
  • 2,225
  • 1
  • 14
  • 30
Rocé Tarentula
  • 653
  • 1
  • 6
  • 15
  • Try [Zxing](https://github.com/zxing/zxing) – SripadRaj Feb 26 '18 at 11:06
  • Possible duplicate of [Integrating the ZXing library directly into my Android application](https://stackoverflow.com/questions/4782543/integrating-the-zxing-library-directly-into-my-android-application) – SripadRaj Feb 26 '18 at 11:08

2 Answers2

1

Add the following dependency to your build.gradle file.:

compile 'me.dm7.barcodescanner:zxing:1.9.8'

Add camera permission to your AndroidManifest.xml file:

<uses-permission android:name="android.permission.CAMERA" />

reference : https://github.com/dm77/barcodescanner

Ali
  • 3,346
  • 4
  • 21
  • 56
1

First of all, there are no public\private keys in QR code. The QR code is only a representation of a data. As such, it can represent an http link (when the data is a string), or a public key for bitcoin transaction (when the data is binary \ string), and other things... Once you get your qr code scanned, you can treat it as a public key and do magic to find related private key, this is not the scope of this answer.

For your question, in order to scan a QR code you can use google-play services. Basically you need to initiate a BarcodeDetector, init a Frame with your bitmap from your camera, and search for barcodes.

code snippet:

BarcodeDetector detector = 
    new BarcodeDetector.Builder(getApplicationContext())
                        .setBarcodeFormats(Barcode.DATA_MATRIX | Barcode.QR_CODE)
                        .build();

if(!detector.isOperational()){
   // we have a problem
   return;
}

Frame frame = new Frame.Builder().setBitmap(yourBitmapHere).build();
SparseArray<Barcode> barcodes = detector.detect(frame);

Barcode qrCode = barcodes.valueAt(0);
String qrCodeValue = qrCode.rawValue;

Go to their full codelab to see more details (including gradle, imports, etc).

Re'em
  • 1,869
  • 1
  • 22
  • 28