EldoS | Feel safer!

Software components for data protection, secure storage and transfer

PGPmime

Also by EldoS: BizCrypto
Components for BizTalk® and SQL Server® Integration Services that let you securely store and transfer information in your business automation solutions.
#7159
Posted: 07/31/2008 10:11:33
by SEBASTIAN MORAGA (Basic support level)
Joined: 07/30/2008
Posts: 5

Hello:
I am a need information about this error.
my code is

Dim msg As TElMessage = Nothing
Dim mpt As TElPlainTextPart = Nothing
Dim mmp As TElMultiPartList = Nothing
Dim ammp As TElMultiPartList = Nothing
Dim par As TElMultiPartList = Nothing
Dim mpc As TElMessagePart = Nothing
Dim pgpmime As New TElMessagePartHandlerPGPMime(Nothing)
SigningKeys = New TElPGPKeyring()
EncryptingKeys = New TElPGPKeyring()
Try

' Make one part message
msg = New TElMessage("")
mpt = New TElPlainTextPart(msg, mmp)
msg.SetMainPart(mpt, False)
mpt.SetText(txtPartPlainText.Text)
msg.From.AddAddress("From e-mail: " + txtFrom.Text, txtFrom.Text)
msg.To_.AddAddress("To e-mail: " + txtTo.Text, txtTo.Text)
msg.SetSubject(txtSubject.Text)
msg.SetDate(DateTime.Now())
msg.MessageID = TElMessage.GenerateMessageID()

msg.MainPart.MessagePartHandler = pgpmime
pgpmime.Encrypt = True
pgpmime.EncryptingKeys = EncryptingKeys
pgpmime.SigningKeys = SigningKeys
Dim res As Integer = msg.AssembleMessage(sm, "utf-8", SBMIME.TElHeaderEncoding.heBase64, "base64", "base64", False)

If res <> 0 Then
Dim ex As New SBPGPExceptions.EElPGPException()
MsgBox("pgpmime: " & pgpmime.ErrorText)
End If

Catch ex As Exception
End Try
End Sub

this error is number = 9 , pgpmime.ErrorText = Recipient's key not found.
Please a need your help.

#7161
Posted: 07/31/2008 10:25:32
by Mykola Olshevsky (Basic support level)
Joined: 07/07/2005
Posts: 450

You should load recipient's public key to the EncryptinKeys. Recipient's public key must match the email address int To_ field.
#7169
Posted: 08/01/2008 06:29:56
by SEBASTIAN MORAGA (Basic support level)
Joined: 07/30/2008
Posts: 5

Another question.
There is a function that a full mime and decodification and the encryption this mime??
#7170
Posted: 08/01/2008 07:17:42
by Eugene Mayevski (EldoS Corp.)

Please re-phrase your question and extend it. So far I could not understand anything.


Sincerely yours
Eugene Mayevski
#7172
Posted: 08/01/2008 07:57:49
by SEBASTIAN MORAGA (Basic support level)
Joined: 07/30/2008
Posts: 5

I need one method to read a type MIME file and
I can encrypt this file .
Has your library this method.
#7174
Posted: 08/01/2008 08:15:22
by SEBASTIAN MORAGA (Basic support level)
Joined: 07/30/2008
Posts: 5

bug??
From: "From e-mail: sebastian.Moraga@ocasa.com"
<sebastian.Moraga@ocasa.com>
To: "To e-mail: Sebastian Mori <sebastian.moraga@ocasa.com>"
<<sebastian.moraga@ocasa.co>Content-Type: multipart/encrypted;
protocol="application/pgp-encrypted";
boundary="----=_NextPart_626_0778_3966104191664236"
MIME-Version: 1.0
#7175
Posted: 08/01/2008 09:07:53
by Eugene Mayevski (EldoS Corp.)

You can't encrypt the message with just one method. See the sample applications for examples of how to create and encrypt MIME and PGP/MIME messages.


Sincerely yours
Eugene Mayevski
#7179
Posted: 08/01/2008 09:50:33
by SEBASTIAN MORAGA (Basic support level)
Joined: 07/30/2008
Posts: 5

thank very much. post script finally

Imports System.IO
Imports System.Text
Imports SBMIMEUtils
Imports SBMIME
Imports SBSMIMECore
Imports SBMIMEStream
Imports SBConstants
Imports SBCustomCertStorage
Imports SBX509
Imports SBRDN
Imports SBUtils
Imports SBPGP
Imports SBPGPMIME
Imports SBPGPKeys

Public Class Form3
Private SigningKeys As New TElPGPKeyring
Private EncryptingKeys As New TElPGPKeyring
Friend WithEvents saveFileDialog As New System.Windows.Forms.SaveFileDialog
Friend WithEvents OpenKeyringDialog As New System.Windows.Forms.OpenFileDialog

Private Sub Form3_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load


End Sub

Private Function ReadText(ByVal ClavePublica As String) As Stream
'de string a stream
Dim bytes As Byte() = System.Text.Encoding.ASCII.GetBytes(ClavePublica)
Dim ms As MemoryStream = New MemoryStream(bytes)
Return (CType(ms, Stream))
End Function
' de stream a string
Private Function createText(ByVal ms As MemoryStream) As String
Dim bytes(ms.Length) As Byte
ms.Position = 0
ms.Read(bytes, 0, ms.Length)
Dim data As String = Encoding.ASCII.GetString(bytes)
Return data
End Function



Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim txtSubject As String = SBMIME.Unit.cXMailerDefaultFieldValue
Dim txtTo As String = "sebastian.Moraga@xxxxxx.com"
Dim txtFrom As String = "sebastian.Moraga@xxxxxxx.com"
Dim txtPartPlainText As String = " texto plano de preuba texto plano de preuba texto plano de preuba texto \n plano de preuba texto plano de preuba texto plano de preuba"
Dim PkApublic As Stream = ReadText("")
Dim PkAsecret As Stream = ReadText(result.Text)
CreatemMime(PkApublic, PkAsecret, txtSubject, txtTo, txtFrom, txtPartPlainText)
'open public key
End Sub


Private Sub CreatemMime(ByVal PkApublic As Object, ByVal PkAsecret As Object, ByVal txtSubject As String, ByVal txtTo As String, ByVal txtFrom As String, ByVal txtPartPlainText As String)
Dim tbPubKeyring As String = ""
SBUtils.Unit.SetLicenseKey(SBUtils.Unit.BytesOfString("0645...589D"))
Try
EncryptingKeys.Load(PkApublic, PkAsecret, False)
Catch ex As Exception
Throw ex
Exit Sub
End Try
If EncryptingKeys.PublicCount < 1 Then
MessageBox.Show("No public keys found")
Else
If EncryptingKeys.PublicKeys(0).UserIDCount > 0 Then
txtTo = EncryptingKeys.PublicKeys(0).UserIDs(0).Name
End If
tbPubKeyring = OpenKeyringDialog.FileName
End If


'save encrypt
Dim sm As Stream = New MemoryStream()
'create
Dim msg As TElMessage = Nothing
Dim mpt As TElPlainTextPart = Nothing
Dim mmp As TElMultiPartList = Nothing
Dim ammp As TElMultiPartList = Nothing
Dim par As TElMultiPartList = Nothing
Dim mpc As TElMessagePart = Nothing
Try
EncryptingKeys.PublicKeys(0).UserIDs(0).Name.Split(" <")

MsgBox(EncryptingKeys.PublicKeys(0).UserIDs(0).Name)

msg = New TElMessage("")
mpt = New TElPlainTextPart(msg, mmp)
msg.SetMainPart(mpt, False)
mpt.SetText(txtPartPlainText)
mpt = New TElPlainTextPart(msg, par)
par = New TElMultiPartList()
par.AddPart(mpt)
mpt.SetText(txtPartPlainText)
msg.From.AddAddress("From e-mail: " + txtFrom, txtFrom)
msg.To_.AddAddress("To e-mail: " + EncryptingKeys.PublicKeys(0).UserIDs(0).Name.Split("<")(0), txtTo.Split("<")(1).Replace(">", ""))
msg.SetSubject(txtSubject)
msg.SetDate(DateTime.Now())
msg.MessageID = TElMessage.GenerateMessageID()
Dim pgpmime As New TElMessagePartHandlerPGPMime(Nothing)
msg.MainPart.MessagePartHandler = pgpmime
pgpmime.Encrypt = True
pgpmime.EncryptingKeys = EncryptingKeys
pgpmime.SigningKeys = SigningKeys
'sm = New FileStream("c:\salida.txt", FileMode.OpenOrCreate, FileAccess.Write)
Dim res As Integer = msg.AssembleMessage(sm, "utf-8", SBMIME.TElHeaderEncoding.heBase64, "base64", "base64", False)
'sm.Flush()
result.Text = createText(sm)
'result.Text = "La mime esta creada en c:\salida.txt"
sm.Close()

Finally
If Not (msg Is Nothing) Then
Dim id As IDisposable = msg
If Not (id Is Nothing) Then
id.Dispose()
End If
End If

End Try
End Sub

End Class
Also by EldoS: CallbackProcess
A component to control process creation and termination in Windows and .NET applications.

Reply

Statistics

Topic viewed 2135 times

Number of guests: 1, registered members: 0, in total hidden: 0




|

Back to top

As of July 15, 2016 EldoS Corporation will operate as a division of /n software inc. For more information, please read the announcement.

Got it!