login about faq

Code:

set crypt = CreateObject("Chilkat.Crypt2")

success = crypt.UnlockComponent("30-day trial")
If (success <> 1) Then
    MsgBox "Crypt component unlock failed"
    WScript.Quit
End If

set cert = CreateObject("Chilkat.Cert")
success = cert.LoadFromFile("keystore.ks")
If (success <> 1) Then
    MsgBox cert.LastErrorText
    WScript.Quit
End If

crypt.SetSigningCert cert

success = crypt.CreateP7M("test.txt","test.p7m")
If (success = 0) Then
    MsgBox crypt.LastErrorText
    WScript.Quit
End If

My keystore is RSA 1024 bit, this is my error:



ChilkatLog:

CreateP7M:

DllDate: Aug  5 2012

UnlockPrefix: 30-day trial

Username: ITACA:ULISSE

Architecture: Little Endian; 32-bit

Language: ActiveX

VerboseLogging: 0

hcCurDate: Tue, 11 Sep 2012 19:07:56 +0200

hcExpire: 11/2012

inFilename: test.txt

outFilename: test.p7m

SigningCert:

  SubjectDN:

  SerialNumber:

--SigningCert

No private key seems to be available for signing (6)

Continuing anyway in case it's a hardware CSP...

Will use CryptoAPI for signing.

msCryptoSignature:

  bDetached: 0

  Microsoft CertCreateCertificateContext function failed.

  WindowsError: Valore tag ASN1 non valido.

  WindowsErrorCode: 0x8009310b

  Failed to get MsCertificate.

--msCryptoSignature

--CreateP7M

--ChilkatLog


Pls help me to understand what is wrong

asked Sep 11 '12 at 13:22

Anto's gravatar image

Anto
1111


My guess is that the keystore.ks does not actually contain a certificate. Examine the cert.LastErrorText after calling cert.LoadFromFile, even though the LoadFromFile method indicates success.

link

answered Sep 11 '12 at 15:37

chilkat's gravatar image

chilkat ♦♦
11.8k316358421

Thanks, this is the messagge:



ChilkatLog:

LoadFromFile:

DllDate: Aug  5 2012

UnlockPrefix: NONE

Username: ITACA:ULISSE

Architecture: Little Endian; 32-bit

Language: ActiveX

VerboseLogging: 0

filename: keystore.ks

fileSize: 1892

Success.

--LoadFromFile

--ChilkatLog


OK

link

answered Sep 11 '12 at 16:20

Anto's gravatar image

Anto
1111

Please send the keystore file to support@chilkatsoft.com (in a zipped attachment). Given that it's named "keystore", I suspect its not a format Chilkat should be able to read. It's probable that the LoadFromFile method should've returned an error.

link

answered Sep 11 '12 at 16:48

chilkat's gravatar image

chilkat ♦♦
11.8k316358421

The keystore.ks seems to be a signed keypair, not a certificate. Try to get the cert + private key in the form of a PFX file (also known as a .p12 file). You can then use the PFX file directly.

link

answered Sep 11 '12 at 22:33

chilkat's gravatar image

chilkat ♦♦
11.8k316358421

For example:

Dim fso, outFile
Set fso = CreateObject("Scripting.FileSystemObject")
Set outFile = fso.CreateTextFile("output.txt", True)

set crypt = CreateObject("Chilkat.Crypt2")

' Any string argument automatically begins the 30-day trial. success = crypt.UnlockComponent("30-day trial") If (success <> 1) Then outFile.WriteLine(crypt.LastErrorText) WScript.Quit End If

set certStore = CreateObject("Chilkat.CertStore")

' Load a PFX file into a certificate store object. success = certStore.LoadPfxFile("myPfx.pfx","pfxPassword") If (success <> 1) Then outFile.WriteLine(certStore.LastErrorText) WScript.Quit End If

' Get the certificate by subject common name. ' This should be the cert within the PFX that also ' has a private key (also stored within the PFX). ' cert is a Chilkat.Cert Set cert = certStore.FindCertBySubjectCN("myCert") If (cert Is Nothing ) Then outFile.WriteLine(certStore.LastErrorText) WScript.Quit End If

' Tell the crypt object to use the certificate for signing: crypt.SetSigningCert cert

' Sign a file, producing a .p7m as output. ' The input file is unchanged, the test.p7m contains the ' contents of the input file and the signature. inFile = "test.txt" outFile = "testp7m" success = crypt.CreateP7M(inFile,outFile) If (success <> 1) Then outFile.WriteLine(crypt.LastErrorText) WScript.Quit End If

MsgBox "Success!" outFile.Close

link

answered Sep 11 '12 at 22:55

chilkat's gravatar image

chilkat ♦♦
11.8k316358421

Your answer
toggle preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Markdown Basics

  • *italic* or __italic__
  • **bold** or __bold__
  • link:[text](http://url.com/ "title")
  • image?![alt text](/path/img.jpg "title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported

Tags:

×5

Asked: Sep 11 '12 at 13:22

Seen: 1,780 times

Last updated: Sep 11 '12 at 22:55

powered by OSQA