Esempio n. 1
0
        /// <summary>
        /// Check validity of audalf data
        /// </summary>
        public static (bool valid, Exception exception) CheckAUDALFbytes(byte[] audalfBytes)
        {
            if (audalfBytes == null)
            {
                return(valid : false, exception : new ArgumentNullException(nameof(audalfBytes)));
            }
            else if (audalfBytes.Length < 1)
            {
                return(valid : false, exception : new ArgumentException($"{nameof(audalfBytes)} does not contain data!"));
            }
            else if (!AUDALF_Deserialize.IsAUDALF(audalfBytes))
            {
                return(valid : false, exception : new ArgumentException($"Not valid AUDALF content!"));
            }

            return(valid : true, exception : null);
        }
Esempio n. 2
0
        private Dictionary <string, object> GetNoteAsDictionary(byte[] derivedPassword)
        {
            var passwordCheck = Helpers.CheckDerivedPassword(derivedPassword);

            if (!passwordCheck.valid)
            {
                throw passwordCheck.exception;
            }

            // Try to decrypt the binary
            byte[] decryptedAUDALF = algorithm.EncryptBytes(this.audalfData, derivedPassword);

            var audalfCheck = Helpers.CheckAUDALFbytes(decryptedAUDALF);

            if (!audalfCheck.valid)
            {
                throw audalfCheck.exception;
            }

            Dictionary <string, object> noteAsDictionary = AUDALF_Deserialize.Deserialize <string, object>(decryptedAUDALF, settings: deserializationSettings);

            return(noteAsDictionary);
        }