I needed to encrypt a few folders on my MacBook (one of the first of the 'just MacBooks', running High Sierra now, though the problem started under the previous OS). I followed the instructions on https://www.hongkiat.com/blog/encrypt-mac-folder/, basically using Disk Utility to create a .dmg. Right after I created it, I unmounted it and then re-opened it to make sure the process worked as advertised. It did, so I deleted the original, unencrypted folder (which is the whole point of the encryption exercise). The next day, I tried to access this .dmg. It asked me for the password, just as it had the day before. The password is absolutely, positively correct, but it wouldn't accept it. I also tried every way I could conceivably have made a mistake. It just gives me an authentication error, as if the password is wrong, which it 100% is not. I've looked through everything I can find for answers, but they're all either talking about external hard drives (with answers involving wiping them completely or unplugging them), or talking about versions of Disk Utility that offer far more options than mine does (many answers involve sparse bundles, which wasn't an option for me). I desperately need these files - and, as a separate problem, my Time Machine has been acting up for ages, so I don't have a recent enough backup to restore from. Please help!
Without backups, all you can do is try variations on your password. The encryption system would be useless if it had a backdoor to circumvent your password.
The password is absolutely, positively correct
I suspect that when you setup the DMG what you actually typed in the password field was not exactly what you thought you typed - and you repeated the error. It is possible to consistently type the wrong password - were you typing very quickly, or were you tired, for example?
Try opening TextEdit and typing in your password many times, see what kind of errors you make when typing quickly, pressing/not pressing shift, variations with Caps Lock set, accidentally pressing two keys instead of one, vary how you were sitting with respect to the keyboard, etc. You can then copy each password variant from TextEdit into the DMG dialog password field to try to open the DMG. Good luck.