Sub encripta_md5_em_rsa_base64(md5_hash As String) As String
Dim ForeignKPG As KeyPairGenerator
Dim c As Cipher
Dim su As StringUtils
Dim Bconv As ByteConverter
Dim ForeignPubKeyString As String
Dim ForeignPubKeyBytes(0) As Byte
Dim MessageBytes(0),MessageBytesEncrypted(0) As Byte
Dim MessageStringEncrypted As String
' inicializa
c.Initialize("RSA")
ForeignKPG.Initialize("RSA", 2048)
ForeignPubKeyString = File.ReadString(File.DirAssets, "pkey.txt").Trim
' converte a chave pública, faz o seu decode
ForeignPubKeyBytes = su.DecodeBase64(ForeignPubKeyString)
ForeignPubKeyString = Bconv.StringFromBytes(ForeignPubKeyBytes, "UTF8")
' instancia a chave
ForeignKPG.publicKeyFromBytes(ForeignPubKeyBytes)
' converte o md5_hash em bytes
MessageBytes = Bconv.StringToBytes(md5_hash, "UTF8")
' encripta
MessageBytesEncrypted = c.encrypt(MessageBytes, ForeignKPG.PublicKey, False)
' encode em Base64
MessageStringEncrypted = su.EncodeBase64(MessageBytesEncrypted)
Return MessageStringEncrypted
End Sub