Skip To Main Content | Home | Sitemap | Contact
Latest Visitors: United States's flagUnited States's flagUnited States's flagUnited States's flagUnited States's flagKorea  Republic of's flagUnited States's flagRussian Federation's flagChina's flagSweden's flagNetherlands's flagUnited States's flagUnited States's flagChina's flagChina's flagPakistan's flagUnited States's flagUnited States's flagUnited States's flagSpain's flagUnited States's flagUnited States's flagUnited States's flagUnited States's flagUnited States's flag
 

How can you Base64 Encode and Decode in classic ASP without a component?

This example uses the library written by Markus Hartsmar in 2002: The original article and code are from http://www.freevbcode.com/ShowCode.asp?ID=5248.  From Wikipedia: "The term Base64 refers to a specific MIME content transfer encoding. It is also used as a generic term for any similar encoding scheme that encodes binary data by treating it numerically and translating it into a base 64 representation. The particular choice of base is due to the history of character set encoding: one can choose a set of 64 characters that is both part of the subset common to most encodings, and also printable. This combination leaves the data unlikely to be modified in transit through systems, such as email, which were traditionally not 8-bit clean."

Provide some data in.

Data In

Base64 Encoded



<%
Option Explicit
Session.CodePage=65001
Response.Charset="UTF-8"
%>
<!--#include virtual="include/base64.asp"-->
<%
Dim dataIn, encoded
if LCase(Request.ServerVariables("HTTP_METHOD"))="post" then
    dataIn=getField("dataIn")
    encoded = base64_encode(dataIn)
end if
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html lang="en">

<head>
<title>Base64 Encoding And Encoding</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta http-equiv="content-language" content="en">
<meta name="language" content="en-US">
<meta name="author" content="Roderick Divilbiss">
<meta name="copyright" content="© 2005-2010 Roderick Divilbiss">
</head>

<body>
<form method="POST" action="<%="http://" & Request.ServerVariables("SERVER_NAME") & Request.ServerVariables("SCRIPT_NAME")%>">
<p>Data In<br><textarea rows="5" name="dataIn" cols="50"><%=dataIn%></textarea></p>
<p><input type="submit" value="Submit" name="B1"></p>
<p>Base64 Encoded<br><textarea rows="5" name="encrypted" cols="50"><%=encoded%></textarea><br>
</p>
</form>
</body>

</html>


This Weeks Most Popular Pages Newest Pages