The hash has to match with the old. IE if the data submitted is 1234 then the encrypted data/base64 needs to equal E59pyTwEJJao6VjsWTBmLGzMr78. How it gets there isn't as important.
The perl function doesn't have to convert the data to unicode and then hash it, if it is simpler it skip certain parts than I'm more than happy to do that. Its the end result that has to match.