Пример #1
0
 public T1 GetValue <T1>(
     byte[] pass,
     CryptConfigFileHelperScryptParameters scryptParameters = null
     )
 {
     try
     {
         return(Encoding.UTF8.GetString(CryptConfigFileHelper.Decrypt(
                                            EncryptedData,
                                            pass,
                                            Salt,
                                            scryptParameters
                                            )).ParseJsonToType <T1>());
     }
     catch (EnumException <CryptConfigFileHelper.EDecryptErrCodes> enumExc)
     {
         if (enumExc.ExceptionCode == CryptConfigFileHelper.EDecryptErrCodes.WrongPassword)
         {
             throw EnumException.Create(
                       EGetValueT1ErrCodes.WrongPassword,
                       innerException: enumExc
                       );
         }
         throw;
     }
 }
Пример #2
0
        public async Task ChangePass(
            byte[] oldPass,
            byte[] newPass,
            CryptConfigFileHelperScryptParameters
            scryptParameters = null
            )
        {
            if (!CheckPass(oldPass))
            {
                throw new ArgumentException(
                          MyNameof.GetLocalVarName(() => oldPass)
                          );
            }
            var originData = GetOriginData(
                oldPass,
                scryptParameters
                );

            Salt = new byte[32];
            MiscFuncs.GetRandomBytes(Salt);
            EncryptedData = CryptConfigFileHelper.Encrypt(
                originData,
                newPass,
                Salt,
                scryptParameters
                );
        }
Пример #3
0
 public byte[] GetOriginData(
     byte[] pass,
     CryptConfigFileHelperScryptParameters scryptParameters = null)
 {
     return(CryptConfigFileHelper.Decrypt(
                EncryptedData,
                pass,
                Salt,
                scryptParameters
                ));
 }
Пример #4
0
 public bool CheckPass(
     byte[] pass,
     CryptConfigFileHelperScryptParameters scryptParameters = null
     )
 {
     try
     {
         CryptConfigFileHelper.Decrypt(
             EncryptedData,
             pass,
             Salt,
             scryptParameters
             );
         return(true);
     }
     catch
     {
         return(false);
     }
 }
Пример #5
0
 public ScryptPassEncryptedData(
     byte[] originData,
     byte[] pass,
     byte[] salt = null,
     CryptConfigFileHelperScryptParameters scryptParameters = null
     )
 {
     if (salt == null)
     {
         salt = new byte[32];
         MiscFuncs.GetRandomBytes(salt);
     }
     if (salt.Length != 32)
     {
         throw new Exception("salt.Length != 32");
     }
     Salt          = salt;
     EncryptedData = CryptConfigFileHelper.Encrypt(
         originData,
         pass,
         salt,
         scryptParameters
         );
 }