Esempio n. 1
0
        public static void Main()
        {
            //the keys are generated by the metadataprocessor.exe in tools directory of the MF
            byte[] modulus = new byte[] { 0x0d, 0x42, 0x27, 0x57, 0xed, 0xbb, 0xdf, 0xe1, 0x51, 0x27, 0xe2, 0x62, 0xd5, 0x60, 0x75, 0x6c, 0x2b, 0x63, 0xd3, 0x45, 0xe3, 0x63, 0x3d, 0x15, 0xf5, 0x4a, 0x38, 0xa7, 0xc9, 0x58, 0x92, 0xac, 0x58, 0xf4, 0x77, 0xc6, 0x68, 0x1f, 0xa8, 0x0b, 0xa6, 0x4a, 0x68, 0xe3, 0xeb, 0xed, 0x89, 0xf4, 0x26, 0x19, 0x92, 0x42, 0x92, 0xd8, 0xec, 0x93, 0xfb, 0xc4, 0x6d, 0x56, 0x16, 0x58, 0xba, 0xf7, 0xc9, 0x87, 0xcc, 0x07, 0x45, 0x57, 0x25, 0xef, 0xb8, 0xeb, 0xbb, 0xa7, 0x2b, 0x83, 0xca, 0x9b, 0xbc, 0xcf, 0x0b, 0x60, 0xd7, 0x8f, 0x7e, 0xdd, 0x28, 0xc5, 0x08, 0x1a, 0xd2, 0x2c, 0x25, 0x70, 0xc8, 0x01, 0x20, 0xc8, 0xc4, 0xaa, 0xf5, 0x65, 0x14, 0x1b, 0xf0, 0x22, 0x25, 0x9e, 0x0e, 0x21, 0xd0, 0xa3, 0xac, 0xb7, 0xaf, 0x35, 0x31, 0x04, 0xb0, 0xfb, 0xdd, 0x09, 0x86, 0xe7, 0x25, 0xcf };
            byte[] privateExponent = new byte[] { 0x41, 0xcd, 0x1d, 0xd3, 0xa7, 0x96, 0xe8, 0xbe, 0xc6, 0x23, 0x42, 0x48, 0x80, 0xc5, 0x62, 0x62, 0x77, 0xac, 0x5c, 0x7c, 0xb9, 0x22, 0xd7, 0x9f, 0xfb, 0x40, 0x59, 0xf2, 0x04, 0xf4, 0xab, 0xa1, 0xf2, 0xba, 0x19, 0xda, 0x51, 0x23, 0x5a, 0x49, 0xf9, 0x22, 0x67, 0x8e, 0xc0, 0x6a, 0x9e, 0x45, 0xc7, 0x20, 0xfa, 0xf3, 0x6d, 0xb9, 0x6e, 0x54, 0x60, 0xff, 0x17, 0xa0, 0x66, 0x71, 0xfb, 0xfa, 0x1b, 0xe2, 0xb2, 0xf2, 0xf9, 0xce, 0xd5, 0x15, 0xaf, 0xf1, 0xb8, 0xfb, 0x36, 0x72, 0x43, 0x07, 0x00, 0xb1, 0xd8, 0xb2, 0x4d, 0x23, 0xc4, 0xc9, 0xac, 0xed, 0xc8, 0xe0, 0xc6, 0x03, 0x7d, 0xc7, 0x1d, 0x1b, 0x73, 0xea, 0xe7, 0x36, 0xc9, 0x4f, 0x7e, 0x28, 0xb8, 0xc4, 0x7c, 0x3f, 0x4d, 0x1c, 0x2d, 0x4f, 0x42, 0xab, 0x8e, 0x4d, 0xac, 0xa3, 0x56, 0x1f, 0xfd, 0x69, 0x13, 0x7e, 0x2f, 0x16 };
            //byte[] publicExponent = new byte[] { 0x01, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
            byte[] publicExponent = new byte[128];
            publicExponent[0] = 0x01;
            publicExponent[2] = 0x01;

            string plainText = "Hello World!";
            byte[] plainBytes = Encoding.UTF8.GetBytes(plainText);

            //Encryption
            Key_RSA encryptor = new Key_RSA(modulus, publicExponent);
            byte[] cipherBytes = encryptor.Encrypt(plainBytes, 0, plainBytes.Length, null);

            //Decryption
            Key_RSA decryptor = new Key_RSA(modulus, privateExponent);
            byte[] restoredBytes = decryptor.Decrypt(cipherBytes, 0, cipherBytes.Length, null);

            //Output
            Debug.Print("Plain Text    : " + new string(Encoding.UTF8.GetChars(plainBytes)));
            Debug.Print("Restored Text : " + new string(Encoding.UTF8.GetChars(restoredBytes)));
            Debug.Print("Plain Bytes   : " + BufferToString(plainBytes));
            Debug.Print("Cipher Bytes  : " + BufferToString(cipherBytes));
            Debug.Print("Restored Bytes: " + BufferToString(restoredBytes));
        }
Esempio n. 2
0
        public static void Main()
        {
            //the keys are generated by the metadataprocessor.exe in tools directory of the MF
            byte[] modulus = new byte[] { 0x15, 0x74, 0x57, 0xb7, 0xb5, 0x9e, 0x62, 0xd9, 0x4f, 0xa2, 0x75, 0x67, 0x60, 0x6b, 0x90, 0xc3, 0x78, 0xb5, 0x23, 0x15, 0x64, 0x1c, 0x45, 0x4e, 0x4f, 0xcd, 0xb3, 0xed, 0x8e, 0x13, 0x01, 0xb1, 0x84, 0xbb, 0xf0, 0x66, 0x5e, 0x7a, 0xe3, 0xfc, 0x13, 0x95, 0x17, 0x5c, 0x63, 0x23, 0xef, 0x0e, 0xa0, 0xdd, 0xc3, 0x51, 0x1c, 0x47, 0x03, 0xed, 0x24, 0x65, 0xe1, 0x16, 0xc9, 0x9d, 0x79, 0x9b, 0x60, 0x2e, 0xb1, 0x8b, 0x6b, 0x7d, 0x8d, 0xdf, 0x23, 0xd8, 0x41, 0xc6, 0x70, 0x8d, 0x86, 0x11, 0x0b, 0x4b, 0x18, 0xc4, 0xbd, 0x75, 0x30, 0x17, 0xfc, 0x2f, 0x36, 0x83, 0x2a, 0x4e, 0x48, 0x41, 0xe3, 0x00, 0x66, 0xc6, 0x2e, 0x32, 0x80, 0x03, 0x11, 0x95, 0xbb, 0x31, 0x66, 0x4e, 0x4d, 0x15, 0xbf, 0xdf, 0x5a, 0xb4, 0xaf, 0xcf, 0xc7, 0xd9, 0xf4, 0x87, 0xd1, 0x1a, 0xa0, 0x77, 0x73, 0xc9 };
            //byte[] publicExponent = new byte[] { 0x01, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
            byte[] publicExponent = new byte[128];
            publicExponent[0] = 0x01;
            publicExponent[2] = 0x01;
            byte[] signature = Resources.GetBytes(Resources.BinaryResources.RsaSignature);

            string messageText = "Hello World!";
            byte[] messageBytes = Encoding.UTF8.GetBytes(messageText);

            //Verification of a signature
            Key_RSA rsa = new Key_RSA(modulus, publicExponent);
            bool valid = rsa.VerifySignature(messageBytes, 0, messageBytes.Length, signature, 0, signature.Length);
            if (valid)
                Debug.Print("Signature is valid.");
            else
                Debug.Print("Signature is NOT valid.");
        }