To set a password directly to an hash i used gsed so far for a long long time. But you never stop to learn. There is a much simpler way. My colleague Detlef Drewanz pointed me to it today : passwd -p <hash> <username>

For example to change my password to changeme123 you use it like this:

#passwd -p $5$xNBPFJQV$78dY0NKeIeF1gHu1LfKIqSodQT.dC.aKMkcbCt9CMl7 jmoekamp
Obviously the usual objections apply:
-p hash
           Specifies  the  exact string value to be placed in the shadow pass-
           word field. The user must have both the  solaris.passwd.assign  and
           solaris.passwd.nocheck  authorizations.  It  is intended to be used
           for scripting password hash updates. Its use is generally  discour-
           aged,  as  the  hashed  password is visible through ps(1) while the
           command runs.
This works in Solaris since Solaris 11.3 SRU 4.