Beispiel #1
0
        private string EncryptImage(Image image, string publicKey)
        {
            byte[] image_byte = ImageToByteArray(image);
            int    length     = image_byte.Length;
            string cypher     = "";
            int    startPoint = 0;

            while (startPoint < (length - 241))
            {
                byte[] segment = new ArraySegment <byte>(image_byte, startPoint, 241).ToArray();
                startPoint += 241;
                var encrypted = RSA_Crypto.EncryptImage(segment, publicKey);
                cypher += Convert.ToBase64String(encrypted) + "~";
            }
            if (startPoint < length)
            {
                int    segmentLength = length - startPoint;
                byte[] segment       = new ArraySegment <byte>(image_byte, startPoint, segmentLength).ToArray();
                //startPoint += 241;
                var encrypted = RSA_Crypto.EncryptImage(segment, publicKey);
                cypher += Convert.ToBase64String(encrypted) + "~";
            }
            return(cypher);
        }
Beispiel #2
0
        private string EncryptImage(Image image)
        {
            byte[] image_byte = ImageToByteArray(image);
            int    length     = image_byte.Length;
            string cypher     = "";
            string publicKey  = ChoosePublicKey(cmbIP.SelectedItem.ToString());
            int    startPoint = 0;

            while (startPoint < (length - 241))
            {
                byte[] segment = new ArraySegment <byte>(image_byte, startPoint, 241).ToArray();
                startPoint += 241;
                var encrypted = RSA_Crypto.EncryptImage(segment, publicKey);
                cypher += Convert.ToBase64String(encrypted) + "|";
                //length = length - 241;
            }
            return(cypher);
        }