Sybase NNTP forums - End Of Life (EOL)

The NNTP forums from Sybase - forums.sybase.com - are now closed.

All new questions should be directed to the appropriate forum at the SAP Community Network (SCN).

Individual products have links to the respective forums on SCN, or you can go to SCN and search for your product in the search box (upper right corner) to find your specific developer center.

Microsoft CAPICOM.dll

10 posts in Objects Last posting was on 2003-03-26 21:18:39.0Z
Michael_M. Posted on 2003-03-25 20:53:05.0Z
Newsgroups: sybase.public.powerbuilder.objects
From: Michael_M.
Date: Tue, 25 Mar 2003 15:53:05 -0500
Subject: Microsoft CAPICOM.dll
Lines: 6
MIME-Version: 1.0
Content-Type: text/plain; charset="us-ascii"
Content-Transfer-Encoding: 7bit
Message-ID: <364_5B165919111C528E0072B8BC85256CF4.0072B92985256CF4@webforums>
Path: forums-1-dub!forums-1-dub!forums-master.sybase.com!webforums.sybase.com!news
Xref: forums-1-dub sybase.public.powerbuilder.objects:7265
Article PK: 734558

Hi,
I'm trying to use CAPICOM object to encrypt and decrypt database password
in .ini file. I registered the CAPICOM.dll on my PC(per MSDN instructions),
but Powerbuilder doesn't see it. I got 'illegal data type' error when
trying to declare the EncryptedData object. Any idea what I'm missing?
Thanks.
Michael


Roy Kiesler [TeamSybase] Posted on 2003-03-25 20:58:31.0Z
Newsgroups: sybase.public.powerbuilder.objects
From: "Roy Kiesler [TeamSybase]" <SPAM_FREE_roy.kiesler@teamsybase.com>
Subject: Re: Microsoft CAPICOM.dll
Date: Tue, 25 Mar 2003 15:58:31 -0500
Lines: 19
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 6.00.2800.1106
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1106
NNTP-Posting-Host: host131.percussion.com 208.252.62.131
Message-ID: <364_#ff1rHx8CHA.313@forums-2-dub>
References: <364_5B165919111C528E0072B8BC85256CF4.0072B92985256CF4@webforums>
Path: forums-1-dub!forums-1-dub!forums-master.sybase.com!forums-2-dub.sybase.com
Xref: forums-1-dub sybase.public.powerbuilder.objects:7266
Article PK: 734554

Can you show us your code?

--
<hopethishelps/>
Roy Kiesler [TeamSybase]
Sybase Developer Network (SDN) -- http://sdn.sybase.com

<Michael_M.> wrote in message
news:5B165919111C528E0072B8BC85256CF4.0072B92985256CF4@webforums...
> Hi,
> I'm trying to use CAPICOM object to encrypt and decrypt database password
> in .ini file. I registered the CAPICOM.dll on my PC(per MSDN
instructions),
> but Powerbuilder doesn't see it. I got 'illegal data type' error when
> trying to declare the EncryptedData object. Any idea what I'm missing?
> Thanks.
> Michael


Michael_M. Posted on 2003-03-25 22:39:51.0Z
Newsgroups: sybase.public.powerbuilder.objects
From: Michael_M.
Date: Tue, 25 Mar 2003 17:39:51 -0500
Subject: Re: Microsoft CAPICOM.dll
Lines: 29
MIME-Version: 1.0
Content-Type: text/plain; charset="us-ascii"
Content-Transfer-Encoding: 7bit
Message-ID: <364_094F47FB82ABC605007C7F6985256CF4.0079057385256CF4@webforums>
References: <364_5B165919111C528E0072B8BC85256CF4.0072B92985256CF4@webforums> <364_#ff1rHx8CHA.313@forums-2-dub>
Path: forums-1-dub!forums-1-dub!forums-master.sybase.com!webforums.sybase.com!news
Xref: forums-1-dub sybase.public.powerbuilder.objects:7267
Article PK: 734555

Thanks for responding to my question!
Um..., I'm very new to this so I tried to mimic the example on MSDN, but I
couldn't get past declaration. I don't really have anything except:

EncryptedData message

Returned error: C0001: Illegal data type: encrypteddata

Here's the VB script from MSDN:

Sub DecryptMessage(ByVal hidden As String, ByVal filename As String)
On Error goto ErrorHandler

Dim message As New EncryptedData
Dim encrypted As String

....
message.SetSecret hidden
message.Decrypt encrypted
MsgBox message.Content
.......
Exit Sub

ErrorHandler:
.......
End Sub

Thanks for your help!
MM


Alex_Osin Posted on 2003-03-26 16:12:55.0Z
Newsgroups: sybase.public.powerbuilder.objects
From: Alex_Osin
Date: Wed, 26 Mar 2003 11:12:55 -0500
Subject: Re: Microsoft CAPICOM.dll
Lines: 51
MIME-Version: 1.0
Content-Type: text/plain; charset="us-ascii"
Content-Transfer-Encoding: 7bit
Message-ID: <364_CBFB85BD8298D01A005912D285256CF5.0081889E85256CF4@webforums>
References: <364_5B165919111C528E0072B8BC85256CF4.0072B92985256CF4@webforums> <364_#ff1rHx8CHA.313@forums-2-dub> <364_094F47FB82ABC605007C7F6985256CF4.0079057385256CF4@webforums>
Path: forums-1-dub!forums-1-dub!forums-master.sybase.com!webforums.sybase.com!news
Xref: forums-1-dub sybase.public.powerbuilder.objects:7274
Article PK: 734566

Hi Michael!

=====

OLEObject oMessage

string TobeEncrypted ,hidden, filename, encryptedmessage

int CAPICOM_ENCRYPTION_ALGORITHM_RC2 = 0
int CAPICOM_ENCRYPTION_ALGORITHM_RC4 = 1
int CAPICOM_ENCRYPTION_ALGORITHM_DES = 2
int CAPICOM_ENCRYPTION_ALGORITHM_3DES = 3
int CAPICOM_ENCRYPTION_ALGORITHM_AES = 4

// Connect to CAPICOM
oMessage = CREATE OLEObject
If oMessage .ConnectToNewObject("CAPICOM.EncryptedData") <> 0 Then
MessageBox("Excel","Could Not Connect To Capicom")
Return
End If

Tobeencrypted = 'ASDVRE'
hidden = 'ALEX'
oMessage.Content = Tobeencrypted
oMessage.SetSecret(hidden)
oMessage.Algorithm.Name = CAPICOM_ENCRYPTION_ALGORITHM_DES
encryptedmessage = oMessage.Encrypt()

If Len(encryptedmessage) < 1 Then
MessageBox("CAPICOM", "no message encrypted. ")
Else
MessageBox("CAPICOM", " Message is " + String(Len(encryptedmessage)) +
" characters")
MessageBox("CAPICOM", " Encrypted message is " + encryptedmessage)

// Open an output file and write the encrypted message to the file.
// The file is not opened if there is no message to write.
// Open filename For Output As #1
// Write #1, encryptedmessage
// Close #1
// MsgBox "Encrypted message written to file "
End If

// Release the EncryptedData object.
oMessage.DisConnectObject()
DESTROY oMessage
==========

HTH

Alex Osin


Michael_M. Posted on 2003-03-26 17:23:13.0Z
Newsgroups: sybase.public.powerbuilder.objects
From: Michael_M.
Date: Wed, 26 Mar 2003 12:23:13 -0500
Subject: Re: Microsoft CAPICOM.dll
Lines: 36
MIME-Version: 1.0
Content-Type: text/plain; charset="us-ascii"
Content-Transfer-Encoding: 7bit
Message-ID: <364_2420A3FE1D34028B005F826E85256CF5.005D8E8685256CF5@webforums>
References: <364_5B165919111C528E0072B8BC85256CF4.0072B92985256CF4@webforums> <364_#ff1rHx8CHA.313@forums-2-dub> <364_094F47FB82ABC605007C7F6985256CF4.0079057385256CF4@webforums> <364_CBFB85BD8298D01A005912D285256CF5.0081889E85256CF4@webforums>
Path: forums-1-dub!forums-1-dub!forums-master.sybase.com!webforums.sybase.com!news
Xref: forums-1-dub sybase.public.powerbuilder.objects:7277
Article PK: 734568

Thanks Alex!
I modified your code a bit to DECRYPT intead of ENCRYPT, but then I got
Powerbuilder error '...error calling of external function decrypt...'. It
seems calling SetSecret function is fine, but Decrypt isn't.
Any thoughts?
Thanks!!!
MM

Below is my code:

string ls_Pswd_Input
integer li_FileNum

// Connect to CAPICOM
oMessage = CREATE OLEObject
IF oMessage.ConnectToNewObject("CAPICOM.EncryptedData") <> 0 THEN
MessageBox("COM Error","Could Not Connect To CAPICOM")
RETURN
END IF

li_FileNum = FileOpen("C:\capitest.txt", StreamMode!)
FileRead(li_FileNum, ls_Pswd_Input)
hidden='password'

IF Len(ls_Pswd_Input) > 0 THEN
oMessage.SetSecret(hidden)
oMessage.Decrypt(ls_Pswd_Input)
encrypted = oMessage.Content
MessageBox("CAPICOM", " Encrypted message is " + encrypted)
ELSE
MessageBox("CAPICOM", "No encrypted message was read in.")
END IF

//Release the EncryptedData object.
oMessage.DisConnectObject()
DESTROY oMessage


Alex_Osin Posted on 2003-03-26 19:32:20.0Z
Newsgroups: sybase.public.powerbuilder.objects
From: Alex_Osin
Date: Wed, 26 Mar 2003 14:32:20 -0500
Subject: Re: Microsoft CAPICOM.dll
Lines: 9
MIME-Version: 1.0
Content-Type: text/plain; charset="us-ascii"
Content-Transfer-Encoding: 7bit
Message-ID: <364_F84F2AB9F3FA431F006B54D985256CF5.00633B4985256CF5@webforums>
References: <364_5B165919111C528E0072B8BC85256CF4.0072B92985256CF4@webforums> <364_#ff1rHx8CHA.313@forums-2-dub> <364_094F47FB82ABC605007C7F6985256CF4.0079057385256CF4@webforums> <364_CBFB85BD8298D01A005912D285256CF5.0081889E85256CF4@webforums> <364_2420A3FE1D34028B005F826E85256CF5.005D8E8685256CF5@webforums>
Path: forums-1-dub!forums-1-dub!forums-master.sybase.com!webforums.sybase.com!news
Xref: forums-1-dub sybase.public.powerbuilder.objects:7281
Article PK: 734571

Michael,

Are you sure you are using the same
=== hidden='password' ====
for encrypt and decrypt?

HTH

Alex Osin


Michael_M. Posted on 2003-03-26 19:59:48.0Z
Newsgroups: sybase.public.powerbuilder.objects
From: Michael_M.
Date: Wed, 26 Mar 2003 14:59:48 -0500
Subject: Re: Microsoft CAPICOM.dll
Lines: 8
MIME-Version: 1.0
Content-Type: text/plain; charset="us-ascii"
Content-Transfer-Encoding: 7bit
Message-ID: <364_6F19C582A7AF7312006DD83485256CF5.006DABB185256CF5@webforums>
References: <364_5B165919111C528E0072B8BC85256CF4.0072B92985256CF4@webforums> <364_#ff1rHx8CHA.313@forums-2-dub> <364_094F47FB82ABC605007C7F6985256CF4.0079057385256CF4@webforums> <364_CBFB85BD8298D01A005912D285256CF5.0081889E85256CF4@webforums> <364_2420A3FE1D34028B005F826E85256CF5.005D8E8685256CF5@webforums> <364_F84F2AB9F3FA431F006B54D985256CF5.00633B4985256CF5@webforums>
Path: forums-1-dub!forums-1-dub!forums-master.sybase.com!webforums.sybase.com!news
Xref: forums-1-dub sybase.public.powerbuilder.objects:7282
Article PK: 734570

Alex,
Yes, I'm sure.
Need I declare the Decrypt methods somewhere? SetSecret seems to work,
though...

BTW, what's 'HTH'?
Thanks so much for your help.
MM


Alex_Osin Posted on 2003-03-26 20:14:01.0Z
Newsgroups: sybase.public.powerbuilder.objects
From: Alex_Osin
Date: Wed, 26 Mar 2003 15:14:01 -0500
Subject: Re: Microsoft CAPICOM.dll
Lines: 81
MIME-Version: 1.0
Content-Type: text/plain; charset="us-ascii"
Content-Transfer-Encoding: 7bit
Message-ID: <364_9862B0178D37CEF6006F257B85256CF5.006EC3EC85256CF5@webforums>
References: <364_5B165919111C528E0072B8BC85256CF4.0072B92985256CF4@webforums> <364_#ff1rHx8CHA.313@forums-2-dub> <364_094F47FB82ABC605007C7F6985256CF4.0079057385256CF4@webforums> <364_CBFB85BD8298D01A005912D285256CF5.0081889E85256CF4@webforums> <364_2420A3FE1D34028B005F826E85256CF5.005D8E8685256CF5@webforums> <364_F84F2AB9F3FA431F006B54D985256CF5.00633B4985256CF5@webforums>
Path: forums-1-dub!forums-1-dub!forums-master.sybase.com!webforums.sybase.com!news
Xref: forums-1-dub sybase.public.powerbuilder.objects:7283
Article PK: 734573

Michael,

1.=========== Encrypting==============
OLEObject oMessage
string TobeEncrypted ,hidden, filename, encryptedmessage, decrypted
int CAPICOM_ENCRYPTION_ALGORITHM_RC2 = 0
int CAPICOM_ENCRYPTION_ALGORITHM_RC4 = 1
int CAPICOM_ENCRYPTION_ALGORITHM_DES = 2
int CAPICOM_ENCRYPTION_ALGORITHM_3DES = 3
int CAPICOM_ENCRYPTION_ALGORITHM_AES = 4
int li_FileNum

// Connect to CAPICOM
oMessage = CREATE OLEObject
If oMessage.ConnectToNewObject("CAPICOM.EncryptedData") <> 0 Then
MessageBox("CAPICOM","Could Not Connect To Capicom")
Return
End If

Tobeencrypted = 'ASDVRE'
hidden = 'password'
oMessage.Content = Tobeencrypted
oMessage.SetSecret(hidden)
oMessage.Algorithm.Name = CAPICOM_ENCRYPTION_ALGORITHM_DES
encryptedmessage = oMessage.Encrypt()

If Len(encryptedmessage) < 1 Then
MessageBox("CAPICOM", "no message encrypted. ")
Else
MessageBox("CAPICOM", " Encrypted message is " + encryptedmessage)
li_FileNum = FileOpen("C:\capitest.txt",StreamMode!, Write!,
LockWrite!, Replace!)
FileWrite(li_FileNum,encryptedmessage)
FileClose(li_FileNum)
End If

// Release the EncryptedData object.
oMessage.DisConnectObject()
DESTROY oMessage
=================================

2. === Decrypting ====================
OLEObject oMessage
string ls_Pswd_Input, hidden, encrypted
integer li_FileNum

// Connect to CAPICOM
oMessage = CREATE OLEObject
IF oMessage.ConnectToNewObject("CAPICOM.EncryptedData") <> 0 THEN
MessageBox("COM Error","Could Not Connect To CAPICOM")
RETURN
END IF

li_FileNum = FileOpen("C:\capitest.txt", StreamMode!)
FileRead(li_FileNum, ls_Pswd_Input)
FileClose(li_FileNum)

hidden='password'

MessageBox("CAPICOM", " Encrypted message is " + ls_Pswd_Input)

IF Len(ls_Pswd_Input) > 0 THEN
oMessage.SetSecret(hidden)
oMessage.Decrypt(ls_Pswd_Input)
encrypted = oMessage.Content
MessageBox("CAPICOM", " Decrypted message is " + encrypted)
ELSE
MessageBox("CAPICOM", "No encrypted message was read in.")
END IF

//Release the EncryptedData object.
oMessage.DisConnectObject()
DESTROY oMessage
========================================

This code works fine for me.

3. Hope This Helps (HTH)

Alex Osin


Michael_M. Posted on 2003-03-26 21:18:39.0Z
Newsgroups: sybase.public.powerbuilder.objects
From: Michael_M.
Date: Wed, 26 Mar 2003 16:18:39 -0500
Subject: Re: Microsoft CAPICOM.dll
Lines: 3
MIME-Version: 1.0
Content-Type: text/plain; charset="us-ascii"
Content-Transfer-Encoding: 7bit
Message-ID: <364_1776A8B8378D9FB6007510A885256CF5.0074710B85256CF5@webforums>
References: <364_5B165919111C528E0072B8BC85256CF4.0072B92985256CF4@webforums> <364_#ff1rHx8CHA.313@forums-2-dub> <364_094F47FB82ABC605007C7F6985256CF4.0079057385256CF4@webforums> <364_CBFB85BD8298D01A005912D285256CF5.0081889E85256CF4@webforums> <364_2420A3FE1D34028B005F826E85256CF5.005D8E8685256CF5@webforums> <364_F84F2AB9F3FA431F006B54D985256CF5.00633B4985256CF5@webforums>
Path: forums-1-dub!forums-1-dub!forums-master.sybase.com!webforums.sybase.com!news
Xref: forums-1-dub sybase.public.powerbuilder.objects:7285
Article PK: 734574

My VB encryption puts double quotes around the message and PB doesn't.
That's why they couldn't decrypt successfully.
MM


Michael_M. Posted on 2003-03-26 21:01:45.0Z
Newsgroups: sybase.public.powerbuilder.objects
From: Michael_M.
Date: Wed, 26 Mar 2003 16:01:45 -0500
Subject: Re: Microsoft CAPICOM.dll
Lines: 8
MIME-Version: 1.0
Content-Type: text/plain; charset="us-ascii"
Content-Transfer-Encoding: 7bit
Message-ID: <364_B5BE363D313E58CD0073848A85256CF5.0072D9AD85256CF5@webforums>
References: <364_5B165919111C528E0072B8BC85256CF4.0072B92985256CF4@webforums> <364_#ff1rHx8CHA.313@forums-2-dub> <364_094F47FB82ABC605007C7F6985256CF4.0079057385256CF4@webforums> <364_CBFB85BD8298D01A005912D285256CF5.0081889E85256CF4@webforums> <364_2420A3FE1D34028B005F826E85256CF5.005D8E8685256CF5@webforums> <364_F84F2AB9F3FA431F006B54D985256CF5.00633B4985256CF5@webforums>
Path: forums-1-dub!forums-1-dub!forums-master.sybase.com!webforums.sybase.com!news
Xref: forums-1-dub sybase.public.powerbuilder.objects:7284
Article PK: 734576

Alex,
Many thanks for your help!
Finally I figured out what the problem was. I had been trying to use PB to
decrypt the message encrypted by VB! I tried to use VB to decrypt a message
encrypted by PB and got an error, too.
I'm a bit surprised by this. Can't PB, with the right key, decrypt
something other app. encrypted by the same algorithm???
MM