tofutim
tofutim

Reputation: 23374

How can I best send encrypted data to a WCF service?

I have been sending encrypted data from my application to my WCF service simply using byte[] as the datatype. However, in a very small fraction of cases I see these kinds of error:

The surrogate pair (0xD8CC, 0xAF1F) is invalid. A high surrogate character (0xD800 – 0xDBFF) must always be paired with a low surrogate character (0xDC00 – 0xDFFF)

The surrogate pair (0xD8AC, 0xE332) is invalid. A high surrogate character (0xD800 - 0xDBFF) must always be paired with a low surrogate characters (0xDC00-0xDFFF).

The surrogate pair (0xD8CC, 0xAAE9) is invalid. A high surrogate character (0xD800 - 0xDBFF) must always be paired with a low surrogate characters (0xDC00-0xDFFF).

Invalid high surrogate character (OxDF44). A high surrogate character must have a value from range(OxD800 - OxDBFF)

After much head scratching, I suspects this results when the encryption results in a sequence of bytes that the WCF XML can't handle. Is there a better way to transmit my encrypted data via WCF? Help!

I suppose the error could be happening either direction. Here's what I have in my .svc.

public byte[] GetEncryptedResult(byte[] encryptedRequest)
{
    return ....
}

Another possibility - is that this is happening not with WCF, but when I encrypted the data. The data is put into XML, encrypted, transmitted via WCF, decrypted into XML.

Can I use DataContractSerializer? Something else?

Upvotes: 0

Views: 671

Answers (2)

competent_tech
competent_tech

Reputation: 44931

We usually convert our encrypted byte data to a base64 string before sending it across the wire.

Upvotes: 1

Andrey Atapin
Andrey Atapin

Reputation: 7945

Probably, you are trying to convert bytes to symbols. Due to encryption you get some weird symbols, which can't be handled with XML processor. I'm not familiar with WCF in depth, but I can recommend conversion bytes to string this way:

{a0, 23, cd, 5e, ff} => "a023cd5eff"

Upvotes: 0

Related Questions