Btw: I wrote a similar script in JavaScript that does not need OpenSSL:
It relies on ObjC so could be re-written in AppleScript easily, I suppose.