How to load a string in a certificate ? (General questions)
Hi weonlydo' mens !
I using SFTP component in VB.NET. that's work great !
However, I coming for a new problem.
Now, in my application, my private key is no more write on a file and I get the ppk on a string.
So, my question is simple : How can I use this sting to use the cert ?
I try :
ftp1 = New wodFtpDLXComLib.wodFtpDLXCom
cert = New WODCERTMNGLib.Certificate
cert.PrivateKey = ppk
And I get :
Failed to import private key.
Howverer, when I compare my file and my string, there is no difference !
Thanks for help !
Bertrand
Re: How to load a string in a certificate ?
Bertrand,
did you try to call wodCertificate's Load method and feed it with BASE64 key data, one that starts with '---- BEGIN ....' ? Can you try that?
Kreso
Re: How to load a string in a certificate ?
Here, what I tryed :
Public Function TexteToBase64(ByVal Texte As String) As String
Try
Dim texteBytes As Byte() = Encoding.ASCII.GetBytes(Texte)
If texteBytes.Length = 0 Then
Return
Else
Return Convert.ToBase64String(texteBytes)
End If
Catch ex As Exception
Return
End Try
End Function
ppk = -----BEGIN RSA PRIVATE KEY----- & vbLf
ppk = ppk & key & vblf
ppk = ppk & -----END RSA PRIVATE KEY----- & vbLf
ftp1 = New wodFtpDLXComLib.wodFtpDLXCom
ftp1.Certificate = TexteToBase64(ppk)
And I got this :
ystem.InvalidCastException: Unable to cast object of type 'System.String' to type 'wodFtpDLXComLib.ICertificate'.
Re: How to load a string in a certificate ?
Hi Bertrand,
Please try something like this using your private key:
[code]
Dim ftp1 As wodFtpDLXComLib.wodFtpDLXCom
ftp1 = New wodFtpDLXComLib.wodFtpDLXCom
Dim cert As WODCERTMNGLib.Certificate
cert = New WODCERTMNGLib.Certificate
Dim KeyData As String
ftp1.Certificate = cert
KeyData = -----BEGIN DSA PRIVATE KEY----- & vbCrLf & _
MIIBugIBAAKBgQCs/Q3P0pu1Ot8LOCTnJ2MeZTRyrjbCaszKiJb3239IABs+svVN & vbCrLf & _
lLNHRR7S+AHtY7CNh/lyhC8tXkX8pK9npjhZh6kesPILCkc5LtqeDaCnC4wchtDO & vbCrLf & _
owmOFEJclpFnyzbJCDnjg+FB5fMDdiNXqJ4bcXIFFLPo3aNrrnulrjJSGwIVAOpg & vbCrLf & _
x+r/mibxlXbPPKUWl7VFosKLAoGAeeXbTM4CtKYqI6AB6nXR07uOumkzyiE5Wb4p & vbCrLf & _
Jw4GxKnTNv8Mc4Xf+rdkbcwXhO/TR2vDj/sXMt9KIi/F6g8hHwrXCBXrPVZwGai0 & vbCrLf & _
fSAdrhU1uxYAug2fbsQ4BsG9pLpYvHUQ4nIINCcl7vfR4ij41/cYtC1nwUlbXHnJ & vbCrLf & _
cNHSh9wCgYBIYciU8r7gMp9pJrBz/zsEcI9CrHWkVB74oGX4hvupXzyj37mM6DpN & vbCrLf & _
py3Xrgl+2OOy0e1uZHHrIeSgV3mIkVbRPPIy/VjZzTm1hs1vtY5BiwHQHNcxRgRk & vbCrLf & _
agrJWOZgHh0haxG7JOxUYSUVsUOeMR4Cgo26B/Su2HK0NMc21Ji0kwIUDr7nYvGg & vbCrLf & _
qKNyluiUbkrQsUYqKso= & vbCrLf & _
-----END DSA PRIVATE KEY-----
cert.LoadKey(KeyData)
Debug.Print(cert.PublicKeyOpenSSH)
[/code]
Let us know how it goes.
Regards,
Drazen
Re: How to load a string in a certificate ?
That's work great Many thanks Drazen !