Rocé Tarentula
Rocé Tarentula

Reputation: 653

Scan QR code - public key

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?

Upvotes: 1

Views: 2131

Answers (2)

Re'em
Re'em

Reputation: 1937

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).

Upvotes: 1

MohammadAli
MohammadAli

Reputation: 3466

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

Upvotes: 1

Related Questions