OWASP ESAPI (OWASP Enterprise Security API)
https://www.owasp.org/index.php/Category:OWASP_Enterprise_Security_API
- Java, .NET, Python, Ruby, PHP, etc.
- Base 64 encoding/decoding is also supported.
P.S. For XSS prevention,
Set cookies HTTP access only and block Javascript access.