示例#1
0
        /// Returns the RSA public key associated to the government that should be used when
        /// encrypting the data that only it should see.
        public static async Task <RSAPublicKey> getGovernmentRsaPubKey(String lcdUrl)
        // public static RSAPublicKey getGovernmentRsaPubKey()
        {
            Object tumblerResponse = await Network.query($"{lcdUrl}/government/tumbler");

            if (tumblerResponse == null)
            {
                System.ArgumentException argEx = new System.ArgumentException("getGovernmentRsaPubKey: Cannot get tumbler address");
                throw argEx;
            }

            TumblerResponse tumbler        = new TumblerResponse(JObject.Parse(tumblerResponse.ToString()));
            String          tumblerAddress = tumbler.result.tumblerAddress;

            Object identityResponseRaw = await Network.query($"{lcdUrl}/identities/{tumblerAddress}");

            if (identityResponseRaw == null)
            {
                System.ArgumentException argEx = new System.ArgumentException("getGovernmentRsaPubKey: Cannot get government RSA public key");
                throw argEx;
            }

            IdentityResponse identityResponse      = new IdentityResponse(JObject.Parse(identityResponseRaw.ToString()));
            String           publicSignatureKeyPem = identityResponse.result.didDocument.publicKeys[1].publicKeyPem;

            RsaKeyParameters rsaPublicKey = RSAKeyParser.parsePublicKeyFromPem(publicSignatureKeyPem);

            return(new RSAPublicKey(rsaPublicKey));
        }
        /// Returns the [PublicKey] that should be used as the public encryption
        /// key when encrypting data that can later be read only by the owner of
        /// this Did Document.
        public RSAPublicKey encryptionKey()
        {
            DidDocumentPublicKey pubKey = publicKeys.FirstOrDefault(key => key.type == "RsaVerificationKey2018");

            if (pubKey == null)
            {
                return(null);
            }
            return(new RSAPublicKey(RSAKeyParser.parsePublicKeyFromPem(pubKey.publicKeyPem)));
            //// If existent, creates the RSA public key
            //BigInteger modulus = new BigInteger(pubKey.publicKeyHex, radix: 16);
            //BigInteger exponent = new BigInteger("65537", radix: 10);
            //return new RSAPublicKey(new RsaKeyParameters(false, modulus, exponent));
        }