lunedì 24 agosto 2020

Decrittare PGP in Kotlin per Android


Un comodo sistema per decrittare messaggi PGP con Kotlin su Android e' quello di usare la libreria https://github.com/Tlaster/KotlinPGP che in pratica e' un wrapper per BountyCastle 

in build.gradle(app)  si aggiunge
 
implementation 'moe.tlaster:kotlinpgp:1.0.20'

il codice e' sostanzialmente autoesplicativo per quanto e' semplice

=================================================

package com.luca.innocenti.pgp_k2

import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.util.Log
import moe.tlaster.kotlinpgp.KotlinPGP

class MainActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
var segreta = "-----BEGIN PGP PRIVATE KEY BLOCK-----\n" +
"\n" +
"lQPFBF9CQ3QBCADVYsnRyqe+2oiaLyZjXzhayQ+GAoGD80jynlwnZQxbSR7thnkz\n" +
"IMg0BtzzQtJMS1Iim/4WRqivWKLRXWupYPMPbH9/6sgAfHnCTfuLtnHDNgfW7A5s\n" +
"GnJQ9/1L9WsS+q8zoSIc8KJ6NCAuYVu3G5hsOwI29GVbh+y0Vr+Bw/QxZbAxS4A2\n" +
"MJhsOsUFU6fJgIjGOwp2Yeie9Bw8cs7CRRhoqYlnbDx1zAmfwLH2VYcAo5PeDLwi\n" +
"KPnKn0i3oBb27eQ5ruYV757m5j8PM75CLlnEeV367LLOYj6nQM3kKoq1Lpc9AOTv\n" +
"vDUOWpF979klsBXM8dxClFZ/PHz3j1LD6DuHABEBAAH+BwMCn6zXeF315vD/wHHD\n" +
"7YaSYS2kpgW4ELMRCQEzLgPRtFRaJIsMYPPiy2Ofc8NGjKA4DwLroKuT6+nSlNiy\n" +
"SrOQh1Lc+J+OZVftDfcyYhFlW222Zpr/0uRVOir1XRNkWC+fy3N03axd/JDb+qXH\n" +
"By3mV/zl563itPQj1NVk3iKDph5dAp0svAMBxDdQORx/XmtqqdIBnAfrBM5S6Trs\n" +
"shYitQ10tFWROu9GKgbbDt1DFS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K-----"

var encryptedData:String = "-----BEGIN PGP MESSAGE-----\n" +
"Version: OpenPGP.js v4.10.4\n" +
"Comment: https://openpgpjs.org\n" +
"\n" +
"wcBMA8AU2yvA99UdAQf+MylbvwaDMuqBneUH8kfMhq5CxCiUwORkZ4sE7/e+\n" +
"CIb+XTc5wYCuTIIqsv8JfcCjLs6fSwjlvEcvjSAn08geiIrquiBbgnkBWPR7\n" +
"iv7CMt6LPzcKfuHt18ZZarEQEf4mwH/DxU+ohYqXpRIuAVbGbcR1n1qWPkto\n" +
"hWDQQLXFZ/fAYKdZekA+SdvISrzpEbS+yy5y0K035oD0aqee6Up93jARvHTk\n" +
"R7kWuBCFoMk23PDTZM+Hv9DNumOXIOm/avZfbVr4I0O0LYlCaq1QOkmV1sfq\n" +
"P2lLD2cGgYp0c6VeLCb9/bbZx/UXPBiakXS3dH09jDE7zUXvk9mrPFz3YlA5\n" +
"M9I/AViN02M0pF83CYzDqCkJ4GkzjAv50bXWzn4ZS0nNR1dl9rY/Ve6KSGiV\n" +
"kTRtpLQ17TI1awzTg4wyifMkrYNW\n" +
"=xPR8\n" +
"-----END PGP MESSAGE-----"

val decrypt = KotlinPGP.decrypt(segreta, "password", encryptedData)
Log.d("test", decrypt.result)

}
}

Nessun commento:

Posta un commento

Debugger integrato ESP32S3

Aggiornamento In realta' il Jtag USB funziona anche sui moduli cinesi Il problema risiede  nell'ID USB della porta Jtag. Nel modulo...