Example #1
0
        public static byte[] Decrypt(byte[] cipherV2Bytes, byte[] publicKey, byte[] privateKey, byte[] privateAuthKey)
        {
            var hashedSharedSecretBytes = VCL.Instance().CalculateAndHashSharedSecret(privateKey, publicKey);
            var authSecretBytes         = VCL.Instance().CalculateAndHashSharedSecret(privateAuthKey, publicKey);
            var keyMaterial64           = ToKeyMaterial64(hashedSharedSecretBytes, authSecretBytes);

            CipherV2 cipherV2FromClient    = VCL.Instance().BinaryDecodeVisualCrypt(cipherV2Bytes, VCL.GetContext()).Result;
            var      binaryDecryptResponse = VCL.Instance().BinaryDecrypt(cipherV2FromClient, keyMaterial64, VCL.GetContext());

            if (!binaryDecryptResponse.IsSuccess && binaryDecryptResponse.Error == LocalizableStrings.MsgPasswordError)
            {
                return(null);
            }
            return(binaryDecryptResponse.Result.GetBytes());
        }
Example #2
0
        public static byte[] Encrypt(byte[] plaintextBytes, byte[] publicKey, byte[] privateKey, byte[] privateAuthKey)
        {
            if (plaintextBytes == null)
            {
                throw new ArgumentNullException(nameof(plaintextBytes));
            }
            if (publicKey == null)
            {
                throw new ArgumentNullException(nameof(publicKey));
            }
            if (privateKey == null)
            {
                throw new ArgumentNullException(nameof(privateKey));
            }

            var hashedSharedSecretBytes = VCL.Instance().CalculateAndHashSharedSecret(privateKey, publicKey);
            var authSecretBytes         = VCL.Instance().CalculateAndHashSharedSecret(privateAuthKey, publicKey);
            var keyMaterial64           = ToKeyMaterial64(hashedSharedSecretBytes, authSecretBytes);

            CipherV2 cipher = VCL.Instance().BinaryEncrypt(new Clearbytes(plaintextBytes), keyMaterial64, new RoundsExponent(RoundsExponent.DontMakeRounds), VCL.GetContext()).Result;

            return(VCL.Instance().BinaryEncodeVisualCrypt(cipher, VCL.GetContext()).Result);
        }