Encrypting with X509SecurityToken

Encrypting with X509SecurityToken

Post by Antonio Di » Fri, 28 Oct 2005 02:13:27

Hi all,

i've got this problem: I can digitally sign a encrypt the comunication
between my client and my service using WSE2.0 sp3. But know i would like
to encrypt some data that the client sends to the service and put it
encrypted in Sql Server. This data will be decrypted again and sent to
some other client.
My problem is: is it possible to use the X509SecurityToken that i get
form ther server certificate to encrypt this data and put it in the DB?


byte[] plainBytes = UTF8Enconding.UTF8.GetBytes(plaintext);

X509SecurityToken token = GetServerToken(certID) as X509SecurityToken;

byte[] encryptedBytes = token.key.EncryptionFormatter.Encrypt(plainBytes);

this gives me an Exception "Bad Length". I know that
AsymmetricEncryption has limits on the size of data that can encrypt but
if i use SymmetricEncryption how can i later decrypt the data again? Do
i store the SymmetricKey encrypted with asymmetric encryption along with
the data encrypted with the symmetric key?


1. can encrypted file be encrypted and then encrypted?

2. Cannot instantiate a X509SecurityToken object in MFC C++


I am trying to incorporate security into my Web Service. I am attempting to
have my client (MFC C++) connect to my .net Web Service (C#) in a secure
manner. The first thing I am doing is trying to obtain a certificate:

//First action to do is to retrieve a certificate that will be added to the
SOAP message
X509CertificateStore *store =
X509CertificateCollection *col =

if( col->Count == 0 )

X509Certificate* cert = col->get_Item(0);
X509SecurityToken* x509st = new X509SecurityToken(cert);

However, I receive the following error:
error C3828: 'Microsoft::Web::Services::Security::X509SecurityToken':
placement arguments not allowed while creating instances of managed classes

Could someone give me any pointers as to what I am doign wrong? Or if
possible, send me some code snippets on how to do this in MFC C++?

Thanks for any help offered!

3. Encrypting a plain text to ciphertext (Encrypted text) in java???

4. Non-encrypted message detected as encrypted

5. Need for separate [encrypted] database for tiny subset of Encrypted fields required?

6. trying to unravel an encrypted string that was encrypted in dotnet managed code.

7. encrypt and decrypt using encrypt(char block[64], int edflag)

8. FREE ~ Encrypted chat server and encrypted BBS access.

9. how to encrypt a plain text string using 3DES / triple DES encrypt

10. Backing up Bitlocker Encrypted Drive Equals Not Encrypted

11. Reinstaled, Lost profiles, encrypted files left encrypted

12. how can we get encrypted file size of an NTFS encrypted file

13. Encrypt in Perl, De-encrypt in Javascript

14. encrypted partition on the hard drive and must be encrypted with F

15. Encrypt the backup, or encrypt the files?