Example #1
0
        private string DoPascalCoinEciesEncrypt(KeyType keyType,
                                                string rawAffineXCoord, string rawAffineYCoord, string payloadToEncrypt)
        {
            // Encryption
            IesCipher cipherEncrypt = new IesCipher(GetEciesPascalCoinCompatibilityEngine());

            cipherEncrypt.Init(true, RecreatePublicKeyFromAffineXandAffineYCoord(keyType,
                                                                                 Hex.Decode(rawAffineXCoord), Hex.Decode(rawAffineYCoord)),
                               GetPascalCoinIesParameterSpec(), SecureRandom);
            return(Hex.ToHexString(cipherEncrypt.DoFinal(Encoding.ASCII.GetBytes
                                                             (payloadToEncrypt))));
        }
Example #2
0
        private string DoPascalCoinEciesDecrypt(KeyType keyType,
                                                string rawPrivateKey, string payloadToDecrypt)
        {
            string result;

            try
            {
                // Decryption
                IesCipher cipherDecrypt = new IesCipher(GetEciesPascalCoinCompatibilityEngine());
                cipherDecrypt.Init(false, RecreatePrivateKeyFromByteArray(keyType,
                                                                          Hex.Decode(rawPrivateKey)),
                                   GetPascalCoinIesParameterSpec(), SecureRandom);

                result = Encoding.ASCII.GetString(cipherDecrypt.DoFinal(Hex.Decode
                                                                            (payloadToDecrypt)));
            }
            catch (Exception e)
            {
                // should only happen if decryption fails
                throw new Exception("Decryption failed", e);
            }

            return(result);
        }