B4J Library SimplePGP - Encrypt, Decrypt, Sign, Verify

This is a wrap around this Github-project.
It wraps the Android Part of it using some additional jars from bouncycastle and spongycastle for the Encryption Provider

I just did it out of curiosity :)
Based on the Size of the Additional jars you need to download them here.

A B4A Version is available here.

SimplePGP4j
Author: DonManfred (wrapper)
Version:
1.0
  • PGPKeyPairGenerator
    • Functions:
      • generateKeyPair (userId As String, password As String, publicKey As java.io_OutputStream, secrectKey As java.io_OutputStream) As Boolean
      • generateKeyPair2 (userId As String, password As String, keySize As Int, publicKey As java.io_OutputStream, secrectKey As java.io_OutputStream) As Boolean

        userId: the user id for the PGP key pair
        password: the password used to secure the secret (private) key
        keySize: the custom key size
        publicKey: the target stream for the public key
        secrectKey: the target stream for the secret (private) key
        Return type: @return:
      • Initialize (EventName As String)
  • PGPMessageEncryptor
    • Functions:
      • decrypt (passwordOfReceiversPrivateKey As String, privateKeyOfReceiver As java.io.InputStream, encryptedData As java.io.InputStream, target As java.io_OutputStream) As Boolean
      • decrypt2 (passwordOfReceiversPrivateKey As String, privateKeyOfReceiver As java.io.InputStream, publicKeyOfSender As java.io.InputStream, encryptedData As java.io.InputStream, target As java.io_OutputStream) As Boolean
      • encrypt (publicKeyOfRecipient As java.io.InputStream, inputDataName As String, plainInputData As java.io.InputStream, target As java.io_OutputStream) As Boolean
      • encrypt2 (publicKeyOfRecipient As java.io.InputStream, privateKeyOfSender As java.io.InputStream, userIdOfSender As String, passwordOfSendersPrivateKey As String, plainInputData As java.io.InputStream, inputDataName As String, target As java.io_OutputStream) As Boolean
      • init (arg0 As Boolean, params As org.spongycastle.crypto.CipherParameters)
      • Initialize (EventName As String)
      • messageDecrypt (arg0 As Byte()) As Byte()
      • messageEncrypt (arg0 As Byte()) As Byte()
  • PGPMessageSigner
    • Functions:
      • Initialize (EventName As String)
      • signMessage (privateKeyOfSender As java.io.InputStream, userIdForPrivateKey As String, passwordOfPrivateKey As String, message As java.io.InputStream, signature As java.io_OutputStream) As Boolean
      • verifyMessage (publicKeyOfSender As java.io.InputStream, message As java.io.InputStream, signatureStream As java.io.InputStream) As Boolean
    • Properties:
      • CompressionAlgorithm As Int [write only]
      • UnlimitedEncryptionStrength As Boolean [write only]


Please note the #AdditionalJar lines...

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
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("Layout1")
    Dim publicKey As OutputStream
    publicKey = File.OpenOutput(File.DirRootExternal,"PublicKey.pem",False)
 
    Dim secretKey As OutputStream
    secretKey = File.OpenOutput(File.DirRootExternal,"SecretKey.pem",False)

    pgpkeys.Initialize("")
    Log(pgpkeys.generateKeyPair("userID","mysecretpassword",publicKey, secretKey))
    'signer.
    'crypt.encrypt(publickeyofreceipient, "Test",plaininputdata, destfile)
End Sub
 

Attachments

  • SimplePGP4jV1.0.zip
    31.4 KB · Views: 656
Last edited:

SMOOTSARA

Active Member
Licensed User
Longtime User
hi
Thank you for publishing this topic :)

can you explain what is applicable and Is it possible to attach an example to this topic.
 

DonManfred

Expert
Licensed User
Longtime User

zapicoj

Member
Licensed User
Longtime User
Awesome @DonManfred, very well done mate! Thanks

I'm currently implementing an application that uses this library in B4A and B4J. Unfortunately, I couldn't find SimplePGP implemented for B4i.

Are you planning to port it to B4i as well? or is there any why to do this sort of things in B4i with any other library at all?

Thanks
 
Top