Solution using BouncyCastle.