Hello!
I am trying to make an application that does encryption of a text. I'm basing on this DonManfred post:
https://www.b4x.com/android/forum/threads/simplepgp-encrypt-decrypt-sign-verify.89521/#post-668497
My code:
Explanation:
Public and private key generation is ok
clear.txt is the file with the text to be encrypted
crip.txt is the file with encrypted text
I don´t understand what is inputDataName parameter in crypt.encrypt (second parameter) (is a string)
The problem is crypt.encrypt method (not working for me)
Any help?
I am trying to make an application that does encryption of a text. I'm basing on this DonManfred post:
https://www.b4x.com/android/forum/threads/simplepgp-encrypt-decrypt-sign-verify.89521/#post-668497
My code:
B4X:
#AdditionalJar: bcpkix-jdk15on-1.58.0.0
#AdditionalJar: bcprov-jdk15on-1.59
#AdditionalJar: bctls-jdk15on-1.58.0.0
#AdditionalJar: pg-1.54.0.0
#AdditionalJar: sc-core-1.58.0.0
#AdditionalJar: sc-prov-1.58.0.0
#AdditionalJar: slf4j-api-1.7.25
Sub Process_Globals
'These global variables will be declared once when the application starts.
'These variables can be accessed from all modules.
End Sub
Sub Globals
'These global variables will be redeclared each time the activity is created.
'These variables can only be accessed from this module.
Dim pgpkeys As PGPKeyPairGenerator
Dim signer As PGPMessageSigner
Dim crypt As PGPMessageEncryptor
Private EditPass As EditText
Private txt1 As EditText
Private txt2 As EditText
Private btnCrypt As Button
Private btnDecrypt As Button
Private btnCls As Button
End Sub
Sub Activity_Create(FirstTime As Boolean)
'Do not forget to load the layout file created with the visual designer. For example:
Activity.LoadLayout("principal")
Dim publicKey As OutputStream
publicKey = File.OpenOutput(File.DirRootExternal,"PublicKey.txt",False)
Dim secretKey As OutputStream
secretKey = File.OpenOutput(File.DirRootExternal,"SecretKey.txt",False)
pgpkeys.Initialize("")
Log(pgpkeys.generateKeyPair("gersonpinto","pass123",publicKey, secretKey))
'signer.
'crypt.encrypt(publickeyofreceipient, "Manfred",plaininputdata, destfile)
End Sub
Sub Activity_Resume
End Sub
Sub Activity_Pause (UserClosed As Boolean)
End Sub
Sub btnCrypt_Click
File.WriteString(File.DirRootExternal, "clear.txt", txt1.Text)
File.WriteString(File.DirRootExternal, "crip.txt", "criptografado")
Dim out As OutputStream = File.OpenOutput(File.DirRootExternal, "crip.txt", False)
Dim pk As InputStream = File.OpenInput(File.DirRootExternal,"PublicKey.txt")
Dim plaindata As InputStream =File.OpenInput(File.DirRootExternal,"clear.txt")
'
crypt.encrypt(pk,"name",plaindata,out)
'
txt2.Text = File.ReadString(File.DirRootExternal,"criptografado.txt")
out.Close
pk.Close
plaindata.Close
End Sub
Explanation:
Public and private key generation is ok
clear.txt is the file with the text to be encrypted
crip.txt is the file with encrypted text
I don´t understand what is inputDataName parameter in crypt.encrypt (second parameter) (is a string)
The problem is crypt.encrypt method (not working for me)
Any help?