Skip to content

Instantly share code, notes, and snippets.

internal Stream TransformToOctetStream(object inputObject, Type inputType, XmlResolver resolver, string baseUri)
{
...
CanonicalXml xml4 = new CanonicalXml((XmlDocument) output, resolver);
return new MemoryStream(xml4.GetBytes());
}
var crypto = require('xml-crypto')
, Dom = require('xmldom').DOMParser
, fs = require('fs')
var xml = fs.readFileSync('./windows_store_signature.xml', 'utf-8');
var doc = new Dom({ignoreWhiteSpace: true}).parseFromString(xml);
xml = doc.firstChild.toString()
var signature = crypto.xpath(doc, "//*//*[local-name(.)='Signature' and namespace-uri(.)='http://www.w3.org/2000/09/xmldsig#']")[0];
var sig = new crypto.SignedXml();
sig.keyInfoProvider = new crypto.FileKeyInfo("./windows_store_certificate.pem");
-----BEGIN CERTIFICATE-----
MIIDyTCCArGgAwIBAgIQNP+YKvSo8IVArhlhpgc/xjANBgkqhkiG9w0BAQsFADCB
jjELMAkGA1UEBhMCVVMxEzARBgNVBAgMCldhc2hpbmd0b24xEDAOBgNVBAcMB1Jl
ZG1vbmQxHjAcBgNVBAoMFU1pY3Jvc29mdCBDb3Jwb3JhdGlvbjEWMBQGA1UECwwN
V2luZG93cyBTdG9yZTEgMB4GA1UEAwwXV2luZG93cyBTdG9yZSBMaWNlbnNpbmcw
HhcNMTExMTE3MjMwNTAyWhcNMzYxMTEwMjMxMzQ0WjCBjjELMAkGA1UEBhMCVVMx
EzARBgNVBAgMCldhc2hpbmd0b24xEDAOBgNVBAcMB1JlZG1vbmQxHjAcBgNVBAoM
FU1pY3Jvc29mdCBDb3Jwb3JhdGlvbjEWMBQGA1UECwwNV2luZG93cyBTdG9yZTEg
MB4GA1UEAwwXV2luZG93cyBTdG9yZSBMaWNlbnNpbmcwggEiMA0GCSqGSIb3DQEB
AQUAA4IBDwAwggEKAoIBAQCcr4/vgqZFtzMqy3jO0XHjBUNx6j7ZTXEnNpLl2VSe
[x] @mentions, #refs, [links](), **formatting**, and <del>tags</del> supported
[x] list syntax required (any unordered or ordered list supported)
@yaronn
yaronn / decrypt
Last active January 24, 2024 00:19
Decrypt SOAP Body encrypted with X.509 certificate with WS-Security (C#).
//decrypt the encryptedKey to get the session key:
//==================================================
string wrappingKey = "put here the value base64 CipherValue under the encryptedKey element";
X509Certificate2 serverCert = new X509Certificate2(File.ReadAllBytes(@"c:\temp\xws-security-server.p12"), "changeit");
RSACryptoServiceProvider rsa = (RSACryptoServiceProvider)serverCert.PrivateKey;
var enckey = rsa.Decrypt(Convert.FromBase64String(wrappingKey), true);
return enckey;
//decrypt the soap body using the session key (aes128):
//see full information and possible error messages here:
http://webservices20.blogspot.co.il/2012/06/12-common-wcf-interop-confusions.html
//This is the most common WCF security setting for interoperability
<customBinding>
<binding name="NewBinding0">
<textMessageEncoding messageVersion="Soap11" />
<security authenticationMode="MutualCertificate" includeTimestamp="false"
messageSecurityVersion="WSSecurity10WSTrustFebruary2005WSSecureConversationFebruary2005WSSecurityPolicy11BasicSecurityProfile10">
<secureConversationBootstrap />
namespace ConsoleApplication309
{
public class B : IEndpointBehavior
{
#region IEndpointBehavior Members
public void AddBindingParameters(ServiceEndpoint endpoint, System.ServiceModel.Channels.BindingParameterCollection bindingParameters)
{
MessagePartSpecification m = new MessagePartSpecification();
@yaronn
yaronn / admin
Created November 29, 2013 18:25
rabbitmq
#rabitmq is already installed in ubuntu
#start/stop/status
$> sudo rabbitmqctl status
OR
$> sudo invoke-rc.d rabbitmq-server status
#enable mgmt console
$> /usr/lib/rabbitmq/lib/rabbitmq_server-2.7.1/sbin/rabbitmq-plugins enable rabbitmq_management
var b = new CustomBinding();
var sec = (AsymmetricSecurityBindingElement)SecurityBindingElement.CreateMutualCertificateBindingElement(MessageSecurityVersion.WSSecurity10WSTrust13WSSecureConversation13WSSecurityPolicy12BasicSecurityProfile10);
sec.EndpointSupportingTokenParameters.Signed.Add(new UserNameSecurityTokenParameters());
sec.MessageSecurityVersion =
MessageSecurityVersion.
WSSecurity10WSTrust13WSSecureConversation13WSSecurityPolicy12BasicSecurityProfile10;
sec.IncludeTimestamp = false;
sec.MessageProtectionOrder = System.ServiceModel.Security.MessageProtectionOrder.EncryptBeforeSign;
using System.Net.Security;
[ServiceContract(..., ProtectionLevel=ProtectionLevel.Sign)]
public interface ServicePortType {...}