recrypt
  :: SB.ByteString -- ^ Original passphrase
  -> SB.ByteString -- ^ New passphrase
  -> SB.ByteString -- ^ New salt
  -> Int           -- ^ New iteration count
  -> SB.ByteString -- ^ Original encoded ciphertext
  -> Either String SB.ByteString -- ^ Either error or new encoded ciphertext
recrypt origPass newPass newSalt newIter etxt = do
  (salt, c, mac, txt) <- decode etxt
  msg <- decrypt origPass salt c mac txt
  return $! encryptAndEncode newPass newSalt newIter msg

-- | Encrypt the input message and return a base64 encoded string containing
-- the encryption parameters along with the ciphertext.
recrypt
  :: SB.ByteString -- ^ Original passphrase
  -> SB.ByteString -- ^ New passphrase
  -> SB.ByteString -- ^ New salt
  -> Int           -- ^ New iteration count
  -> SB.ByteString -- ^ Original encoded ciphertext
  -> Either String SB.ByteString
recrypt origPass newPass newSalt newIter etxt = do
  (salt, c, mac, txt) <- decode etxt
  msg <- decrypt origPass salt c mac txt
  return $! encryptAndEncode newPass newSalt newIter msg

-- | Encrypt the input message and return a base64 encoded string containing
-- the encryption parameters along with the ciphertext.
recrypt origPass newPass newSalt newIter etxt = do
  (salt, c, mac, txt) <- decode etxt
  msg <- decrypt origPass salt c mac txt
  return $! encryptAndEncode newPass newSalt newIter msg

-- | Encrypt the input message and return a base64 encoded string containing
-- the encryption parameters along with the ciphertext.