Ejemplo n.º 1
0
        private string AsymmetricNewKey(string secret, int keysize)
        {
            Asymmetric asym;
             Asymmetric asym2;
             if (keysize == 0)
             {
            asym = new Asymmetric();
            asym2 = new Asymmetric();
             }
             else
             {
            asym = new Asymmetric(keysize);
            asym2 = new Asymmetric(keysize);
             }

             var keyPair = Asymmetric.GenerateNewKeyset();
             var pubkey = keyPair.Key;
             var privkey = keyPair.Value;

             Data encryptedData = asym.Encrypt(new Data(secret), pubkey);
             Data decryptedData = asym2.Decrypt(encryptedData, privkey);

             return decryptedData.ToString();
        }
Ejemplo n.º 2
0
        private string AsymmetricXmlKey(string secret)
        {
            string publicKeyXml = "<RSAKeyValue>" + "<Modulus>0D59Km2Eo9oopcm7Y2wOXx0TRRXQFybl9HHe/ve47Qcf2EoKbs9nkuMmhCJlJzrq6ZJzgQSEbpVyaWn8OHq0I50rQ13dJsALEquhlfwVWw6Hit7qRvveKlOAGfj8xdkaXJLYS1tA06tKHfYxgt6ysMBZd0DIedYoE1fe3VlLZyE=</Modulus>" + "<Exponent>AQAB</Exponent>" + "</RSAKeyValue>";

             string privateKeyXml = "<RSAKeyValue>" + "<Modulus>0D59Km2Eo9oopcm7Y2wOXx0TRRXQFybl9HHe/ve47Qcf2EoKbs9nkuMmhCJlJzrq6ZJzgQSEbpVyaWn8OHq0I50rQ13dJsALEquhlfwVWw6Hit7qRvveKlOAGfj8xdkaXJLYS1tA06tKHfYxgt6ysMBZd0DIedYoE1fe3VlLZyE=</Modulus>" + "<Exponent>AQAB</Exponent>" + "<P>/1cvDks8qlF1IXKNwcXW8tjTlhjidjGtbT9k7FCYug+P6ZBDfqhUqfvjgLFF/+dAkoofNqliv89b8DRy4gS4qQ==</P>" + "<Q>0Mgq7lyvmVPR1r197wnba1bWbJt8W2Ki8ilUN6lX6Lkk04ds9y3A0txy0ESya7dyg9NLscfU3NQMH8RRVnJtuQ==</Q>" + "<DP>+uwfRumyxSDlfSgInFqh/+YKD5+GtGXfKtO4hu4xF+8BGqJ1YXtkL+Njz2zmADOt5hOr1tigPSQ2EhhIqUnAeQ==</DP>" + "<DQ>M5Ofd28SOjCIwCHjwG+Q8v1qzz3CBNljI6uuEGoXO3ixbkggVRfKcMzg2C6AXTfeZE6Ifoy9OyhvLlHTPiXakQ==</DQ>" + "<InverseQ>yQIJMLdL6kU4VK7M5b5PqWS8XzkgxfnaowRs9mhSEDdwwWPtUXO8aQ9G3zuiDUqNq9j5jkdt77+c2stBdV97ew==</InverseQ>" + "<D>HOpQXu/OFyJXuo2EY43BgRt8bX9V4aEZFRQqrqSfHOp8VYASasiJzS+VTYupGAVqUPxw5V1HNkOyG0kIKJ+BG6BpIwLIbVKQn/ROs7E3/vBdg2+QXKhikMz/4gYx2oEsXW2kzN1GMRop2lrrJZJNGE/eG6i4lQ1/inj1Tk/sqQE=</D>" + "</RSAKeyValue>";

             Data encryptedData;
             Data decryptedData;
             Asymmetric asym = new Asymmetric();
             Asymmetric asym2 = new Asymmetric();

             encryptedData = asym.Encrypt(new Data(secret), publicKeyXml);
             decryptedData = asym2.Decrypt(encryptedData, privateKeyXml);

             return decryptedData.ToString();
        }
Ejemplo n.º 3
0
        private string AsymmetricConfigKey(string secret)
        {
            Data encryptedData;
             Data decryptedData;
             Asymmetric asym = new Asymmetric();
             Asymmetric asym2 = new Asymmetric();

             encryptedData = asym.Encrypt(new Data(secret));
             decryptedData = asym2.Decrypt(encryptedData);

             return decryptedData.ToString();
        }