0

I have written a program to encrypt and decrypt appdata in an app.config file. The program is working correctly so I could encrypt app.config like this

<configProtectedData>
        <providers>
          <add keyContainerName="MyConfigurationKey"
          description="Uses RsaCryptoServiceProvider to encrypt and decrypt"
          name="MyProtectedConfigurationprovider"
          type="System.Configuration.RsaProtectedConfigurationProvider,System.Configuration, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
        </providers>
      </configProtectedData>
      <appSettings configProtectionProvider="MyRSAProtectedConfigurationprovider">
        <EncryptedData Type="http://www.w3.org/2001/04/xmlenc#Element"
          xmlns="http://www.w3.org/2001/04/xmlenc#">
          <EncryptionMethod Algorithm="http://www.w3.org/2001/04/xmlenc#tripledes-cbc" />
          <KeyInfo xmlns="http://www.w3.org/2000/09/xmldsig#">
            <EncryptedKey xmlns="http://www.w3.org/2001/04/xmlenc#">
              <EncryptionMethod Algorithm="http://www.w3.org/2001/04/xmlenc#rsa-1_5" />
              <KeyInfo xmlns="http://www.w3.org/2000/09/xmldsig#">
                <KeyName>Rsa Key</KeyName>
              </KeyInfo>
              <CipherData>
                <CipherValue> Some long text </CipherValue>
              </CipherData>
            </EncryptedKey>
          </KeyInfo>
          <CipherData>
            <CipherValue> very long text</CipherValue>
          </CipherData>
        </EncryptedData>
      </appSettings>

After that I exported the key.Result which is this:

<RSAKeyValue>
    <Modulus>Some text</Modulus>
    <Exponent>AQAB</Exponent>
    <P>Some text</P>
    <Q>Some text</Q>
<DP>Some text</DP>
<DQ>Some text</DQ>
<InverseQ>Some text</InverseQ>
<D>Some text</D>
</RSAKeyValue>

Now, I need to find the private key and public key in encryption. I searched several places but I could not find a proper document about it. Please help me on this.

Nayana Priyankara
  • 1,392
  • 1
  • 18
  • 26
  • 2
    What _did_ you find when you searched? Why did what you found not apply here? Did you look in MSDN for APIs related to encryption? – Peter Duniho Nov 10 '14 at 08:38
  • I used the answer to below question to do this. https://social.msdn.microsoft.com/Forums/en-US/d43a4bd7-7cc1-40cf-8269-82c92894df43/encrypt-section-of-appconfig-decrypt-on-other-machine?forum=csharplanguage I found how to export the but I could not found a document which describing which part is private key, which part is bublic key – Nayana Priyankara Nov 10 '14 at 08:42
  • I found a answer in here. But I am not sure is it correct or not http://stackoverflow.com/questions/17693289/rsa-key-values-and-modulus-in-public-private-keys – Nayana Priyankara Nov 10 '14 at 09:38

1 Answers1

1

I'm not sure what format you are expecting the key to be in, but key.Result contains all the information you are looking for. The tuple Modulus and Exponent are the public RSA key and the tuple Modulus and D the private key. From what I can see in the Exponent data field, the numbers are base64 encoded: AQAB is the base64 encoding of '\x01\x00\x01', which is the encoding of a commonly used public exponent 65537. I can't tell whether it's little or big endian, though.

Perseids
  • 12,584
  • 5
  • 40
  • 64
  • @parseids Is there any trustered source describing this – Nayana Priyankara Nov 11 '14 at 04:18
  • 1
    @Nayanna: Any textbook about cryptography covering RSA, e.g. [Understanding Cryptography by Christof Paar and Jan Pelzl](https://en.wikipedia.org/wiki/Special:BookSources/9783642041006). But for practical uses you always need to convert it to a format that your target application understands. The x.509 PEM or DER format is vastly different to the PGP key format, for example. If you would explain what you intend to do with the key, we might be able to provide more specific help. – Perseids Nov 11 '14 at 09:24
  • thank you very much for answering. I am new to cryptography.I needed to do encrypt app.config files in a web farm scenario. I could be able to do it successfully. But then I needed to encrypt using my own key. So I thought to export key and edit private and public keys and import it again.Is it a good way to it or is their any better way. Thanks very much again. – Nayana Priyankara Nov 11 '14 at 09:52
  • 1
    @Nayanna: You should exchange the whole content of the file, afaikt it also contains [some derived values](https://en.wikipedia.org/wiki/RSA_%28cryptosystem%29#Using_the_Chinese_remainder_algorithm) to speed up decryption. Regarding the security implications of your idea, I can't really tell, as I don't know the threat scenario for such a setup well enough. Maybe you can ask a separate question regarding this aspect, containing what data you want to protect from whom and who still has to have access. I believe the configuration has still to be readable by the server to start the application? – Perseids Nov 11 '14 at 10:28