Пример #1
0
        /// <summary>
        /// Creates a factory using service credentials. Allows interacting with just services, as service credentials have no child services or directories.
        /// </summary>
        /// <param name="serviceId">The unique service ID of the service</param>
        /// <param name="privateKeyPem">The private key to use. Should be the key itself -- not a path.</param>
        /// <returns>A configured ServiceFactory, ready to create ServiceClients</returns>
        public ServiceFactory MakeServiceFactory(string serviceId, string privateKeyPem)
        {
            var key         = _crypto.LoadRsaPrivateKey(privateKeyPem);
            var keys        = new Dictionary <string, RSA>();
            var id          = new EntityIdentifier(EntityType.Service, Guid.Parse(serviceId));
            var fingerprint = _crypto.GeneratePublicKeyFingerprintFromPrivateKey(key);

            keys.Add(fingerprint, key);
            return(new ServiceFactory(MakeTransport(id, keys, fingerprint), Guid.Parse(serviceId)));
        }
Пример #2
0
        public void TestLoadPrivateKey()
        {
            var pkey = @"-----BEGIN RSA PRIVATE KEY-----
MIIEpAIBAAKCAQEAkWY1n5mCrzLjys1zijQwhTeZwXMajWg7kE4KD6m7KBCtkqoO
nL6rnlRELsWpKsKujFjWIqE4V2rJEV+ctZK/xThFgEURYQ8Tl5QLJN8anp+9eot8
E9s5A8zjfBf3lq+BmzDJDOaCg+ZgmoPbx6t0t6Y76kSMuP1UoRp4B/OFB1WETDQM
rzc8vwgJb+LC9fDHYIMk3aKbYVI1FHYPC0QGw1EgfmpqYnWkhDb8y9YZMMaVAYQF
YCrELy77DBEhkGFoyIlbHJA8ZMSJgMNeY3Soq2dQRcwseKCSy0h7ugB/10+Hst2N
oDLMjXw3IevbUisQoeE32kJm0jTg2CgjfNXE4wIDAQABAoIBAHrilH2QA3hJHWbA
n1713vAoXsW1n4JVzsmWe0Bjpi8lcV1cZr8pEujctUeGfQQLx/QL/OcFtRWExezu
DwcSwQtRFMRlG1wZnuhkEcsW2Gup/D0++B3cEOLaXoT5yKJNMM/VuoYxp6sMoSbW
PIETsrCoSUkkqH6MdOM3+KxXr13TLb5uwdW+7XCuJZhqtpW1BfXyLsODfTJ9dTeK
HCbsaAc8aYb3T++I2VZ1CnjY65u5Ve7EEmKhmdAwPAkv3nAV2M/WejnhvM5WxEIF
e4XLrl/BGGHrO23iJfsh4U0JiqiRKK+pZ5/OS0IjClHOcAqXPpXlAOAl60EB8sDi
prLht2kCgYEAv8FR0IGl8+wXt+y8enj+wRw77keX60amZI0BP/6T2DG4Iifbeutz
FEjZjr9lQRucbguYQZQvNCUD3bcJhLycKjnWlLx1rFYiKr+InVGjdxDgTXytmfXv
5cwjtuPutjLmtSB6G7eyjT541nAY5eLgUsQmG6GJGjuXFbk68E/hul8CgYEAwhz7
oFX++WBG6rcJppd8ZSh+22qxM2ujb74rFkSA+ElkmLvuJWcUWCKP9NKLrSzNFC56
hPf6ahTV32W3D1yV2jH8uD13vaRl81Ibf6joyZ1NjlLzF8f80kxhTv9sBYXCFoE0
N65bv4pBOH1j5W8JU+VENG4e/yPmphwYmw3Ri/0CgYEAqzlcbOrX3O88XqetxU61
bIphmWukZBo6Ch8+tn4EVlBPM3CTszb7E2nZmnWdXH3jOQBxfF1tqQpEYX5HqZch
ezMaQMXn7XMcHz/YJWH4rSEMqSRjf87z4CZg3ba6OUdKawINByMI9MaL8C84jE4C
MOWlgZbEbgA38NXtoxgxX9ECgYBoAnehlfKlVL0rDyCQryLsYSJ4F1cTol1UhqU3
rUUdxNWuMSSNzgnMn9ha6mYFSLgqVC06ClWXecqPhUTtakKxQ4+SeP0sFGa8VgZ+
BNeXED56QGAZIgOJ+3s4hQwweVdiD6EXJMnse/wudKGOUkzBM1u0bD0XoPj5kJxu
mJzrUQKBgQCkUZ3gzA90Pf3dogYn0mGfTj4hY/+qn3tGtc0CFrzGHdIEFnJi5WlO
r+ppoKXL4tSFNDsShVSQBgEAZU9F/F7wUgCXqBMnHu574fpKakiNpeTmLnQ4JNn4
PmRoieUCtxxvmnckMGk4ub+/X4AJHb0ErqavEbIrrBNLW4ahtrJC5g==
-----END RSA PRIVATE KEY-----";
            var key  = _crypto.LoadRsaPrivateKey(pkey);
            var csp  = key as RSACryptoServiceProvider;

            Assert.IsTrue(csp != null);
            Assert.AreEqual(2048, csp.KeySize);
            Assert.AreEqual(false, csp.PublicOnly);
        }
Пример #3
0
 public void Setup()
 {
     _crypto     = new BouncyCastleCrypto();
     _publicKey  = _crypto.LoadRsaPublicKey(File.ReadAllText("test-public.key"));
     _privateKey = _crypto.LoadRsaPrivateKey(File.ReadAllText("test-private.key"));
 }