<!DOCTYPE html> <html class="writer-html5" lang="en" > <head> <meta charset="utf-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Security and Internet Functions — Ring 1.14 documentation</title> <link rel="stylesheet" href="_static/css/theme.css" type="text/css" /> <link rel="stylesheet" href="_static/pygments.css" type="text/css" /> <link rel="stylesheet" href="_static/css/custom.css" type="text/css" /> <!--[if lt IE 9]> <script src="_static/js/html5shiv.min.js"></script> <![endif]--> <script type="text/javascript" id="documentation_options" data-url_root="./" src="_static/documentation_options.js"></script> <script src="_static/jquery.js"></script> <script src="_static/underscore.js"></script> <script src="_static/doctools.js"></script> <script src="_static/language_data.js"></script> <script type="text/javascript" src="_static/js/theme.js"></script> <link rel="index" title="Index" href="genindex.html" /> <link rel="search" title="Search" href="search.html" /> <link rel="next" title="Object Oriented Programming (OOP)" href="oop.html" /> <link rel="prev" title="PostgreSQL Functions" href="postgresql.html" /> </head> <body class="wy-body-for-nav"> <div class="wy-grid-for-nav"> <nav data-toggle="wy-nav-shift" class="wy-nav-side"> <div class="wy-side-scroll"> <div class="wy-side-nav-search" > <a href="index.html"> <img src="_static/ringdoclogo.jpg" class="logo" alt="Logo"/> </a> <div role="search"> <form id="rtd-search-form" class="wy-form" action="search.html" method="get"> <input type="text" name="q" placeholder="Search docs" /> <input type="hidden" name="check_keywords" value="yes" /> <input type="hidden" name="area" value="default" /> </form> </div> </div> <div class="wy-menu wy-menu-vertical" data-spy="affix" role="navigation" aria-label="main navigation"> <ul class="current"> <li class="toctree-l1"><a class="reference internal" href="ringapps.html">Applications developed in a few hours</a></li> <li class="toctree-l1"><a class="reference internal" href="introduction.html">Introduction</a></li> <li class="toctree-l1"><a class="reference internal" href="ringnotepad.html">Using Ring Notepad</a></li> <li class="toctree-l1"><a class="reference internal" href="getting_started.html">Getting Started - First Style</a></li> <li class="toctree-l1"><a class="reference internal" href="getting_started2.html">Getting Started - Second Style</a></li> <li class="toctree-l1"><a class="reference internal" href="getting_started3.html">Getting Started - Third Style</a></li> <li class="toctree-l1"><a class="reference internal" href="variables.html">Variables</a></li> <li class="toctree-l1"><a class="reference internal" href="operators.html">Operators</a></li> <li class="toctree-l1"><a class="reference internal" href="controlstructures.html">Control Structures - First Style</a></li> <li class="toctree-l1"><a class="reference internal" href="controlstructures2.html">Control Structures - Second Style</a></li> <li class="toctree-l1"><a class="reference internal" href="controlstructures3.html">Control Structures - Third Style</a></li> <li class="toctree-l1"><a class="reference internal" href="getinput.html">Getting Input</a></li> <li class="toctree-l1"><a class="reference internal" href="functions.html">Functions - First Style</a></li> <li class="toctree-l1"><a class="reference internal" href="functions2.html">Functions - Second Style</a></li> <li class="toctree-l1"><a class="reference internal" href="functions3.html">Functions - Third Style</a></li> <li class="toctree-l1"><a class="reference internal" href="programstructure.html">Program Structure</a></li> <li class="toctree-l1"><a class="reference internal" href="lists.html">Lists</a></li> <li class="toctree-l1"><a class="reference internal" href="strings.html">Strings</a></li> <li class="toctree-l1"><a class="reference internal" href="dateandtime.html">Date and Time</a></li> <li class="toctree-l1"><a class="reference internal" href="checkandconvert.html">Check Data Type and Conversion</a></li> <li class="toctree-l1"><a class="reference internal" href="mathfunc.html">Mathematical Functions</a></li> <li class="toctree-l1"><a class="reference internal" href="files.html">Files</a></li> <li class="toctree-l1"><a class="reference internal" href="systemfunc.html">System Functions</a></li> <li class="toctree-l1"><a class="reference internal" href="evaldebug.html">Eval() and Debugging</a></li> <li class="toctree-l1"><a class="reference internal" href="demo.html">Demo Programs</a></li> <li class="toctree-l1"><a class="reference internal" href="odbc.html">ODBC Functions</a></li> <li class="toctree-l1"><a class="reference internal" href="mysql.html">MySQL Functions</a></li> <li class="toctree-l1"><a class="reference internal" href="sqlite.html">SQLite Functions</a></li> <li class="toctree-l1"><a class="reference internal" href="postgresql.html">PostgreSQL Functions</a></li> <li class="toctree-l1 current"><a class="current reference internal" href="#">Security and Internet Functions</a><ul> <li class="toctree-l2"><a class="reference internal" href="#md5-function">MD5() Function</a></li> <li class="toctree-l2"><a class="reference internal" href="#sha1-function">SHA1() Function</a></li> <li class="toctree-l2"><a class="reference internal" href="#sha256-function">SHA256() Function</a></li> <li class="toctree-l2"><a class="reference internal" href="#sha512-function">SHA512() Function</a></li> <li class="toctree-l2"><a class="reference internal" href="#sha384-function">SHA384() Function</a></li> <li class="toctree-l2"><a class="reference internal" href="#sha224-function">SHA224() Function</a></li> <li class="toctree-l2"><a class="reference internal" href="#encrypt-function">Encrypt() Function</a></li> <li class="toctree-l2"><a class="reference internal" href="#decrypt-function">Decrypt() Function</a></li> <li class="toctree-l2"><a class="reference internal" href="#encryption-and-decryption-example">Encryption and Decryption Example</a></li> <li class="toctree-l2"><a class="reference internal" href="#file-hash">File Hash</a></li> <li class="toctree-l2"><a class="reference internal" href="#randbytes-function">Randbytes() Function</a></li> <li class="toctree-l2"><a class="reference internal" href="#large-files-hash">Large Files Hash</a></li> <li class="toctree-l2"><a class="reference internal" href="#download-function">Download() Function</a></li> <li class="toctree-l2"><a class="reference internal" href="#sendemail-function">SendEmail() Function</a></li> </ul> </li> <li class="toctree-l1"><a class="reference internal" href="oop.html">Object Oriented Programming (OOP)</a></li> <li class="toctree-l1"><a class="reference internal" href="fp.html">Functional Programming (FP)</a></li> <li class="toctree-l1"><a class="reference internal" href="metaprog.html">Reflection and Meta-programming</a></li> <li class="toctree-l1"><a class="reference internal" href="declarative.html">Declarative Programming using Nested Structures</a></li> <li class="toctree-l1"><a class="reference internal" href="natural.html">Natural language programming</a></li> <li class="toctree-l1"><a class="reference internal" href="naturallibrary.html">Using the Natural Library</a></li> <li class="toctree-l1"><a class="reference internal" href="scope.html">Scope Rules for Variables and Attributes</a></li> <li class="toctree-l1"><a class="reference internal" href="scope2.html">Scope Rules for Functions and Methods</a></li> <li class="toctree-l1"><a class="reference internal" href="syntaxflexibility.html">Syntax Flexibility</a></li> <li class="toctree-l1"><a class="reference internal" href="typehints.html">The Type Hints Library</a></li> <li class="toctree-l1"><a class="reference internal" href="debug.html">The Trace Library and the Interactive Debugger</a></li> <li class="toctree-l1"><a class="reference internal" href="ringemb.html">Embedding Ring Language in Ring Programs</a></li> <li class="toctree-l1"><a class="reference internal" href="stdlib.html">Stdlib Functions</a></li> <li class="toctree-l1"><a class="reference internal" href="stdlibclasses.html">Stdlib Classes</a></li> <li class="toctree-l1"><a class="reference internal" href="qt.html">Desktop, WebAssembly and Mobile development using RingQt</a></li> <li class="toctree-l1"><a class="reference internal" href="formdesigner.html">Using the Form Designer</a></li> <li class="toctree-l1"><a class="reference internal" href="qt3d.html">Graphics Programming using RingQt3D</a></li> <li class="toctree-l1"><a class="reference internal" href="ringqtobjects.html">Objects Library for RingQt Application</a></li> <li class="toctree-l1"><a class="reference internal" href="multilanguage.html">Multi-language Applications</a></li> <li class="toctree-l1"><a class="reference internal" href="qtmobile.html">Building RingQt Applications for Mobile</a></li> <li class="toctree-l1"><a class="reference internal" href="qtwebassembly.html">Building RingQt Applications for WebAssembly</a></li> <li class="toctree-l1"><a class="reference internal" href="web.html">Web Development (CGI Library)</a></li> <li class="toctree-l1"><a class="reference internal" href="deployincloud.html">Deploying Web Applications in the Cloud</a></li> <li class="toctree-l1"><a class="reference internal" href="allegro.html">Graphics and 2D Games programming using RingAllegro</a></li> <li class="toctree-l1"><a class="reference internal" href="gameengine.html">Demo Project - Game Engine for 2D Games</a></li> <li class="toctree-l1"><a class="reference internal" href="gameengineandorid.html">Building Games For Android</a></li> <li class="toctree-l1"><a class="reference internal" href="ringraylib.html">Developing Games using RingRayLib</a></li> <li class="toctree-l1"><a class="reference internal" href="usingopengl.html">Using RingOpenGL and RingFreeGLUT for 3D Graphics</a></li> <li class="toctree-l1"><a class="reference internal" href="usingopengl2.html">Using RingOpenGL and RingAllegro for 3D Graphics</a></li> <li class="toctree-l1"><a class="reference internal" href="goldmagic800.html">Demo Project - The Gold Magic 800 Game</a></li> <li class="toctree-l1"><a class="reference internal" href="tilengine.html">Using RingTilengine</a></li> <li class="toctree-l1"><a class="reference internal" href="performancetips.html">Performance Tips</a></li> <li class="toctree-l1"><a class="reference internal" href="compiler.html">Command Line Options</a></li> <li class="toctree-l1"><a class="reference internal" href="distribute.html">Distributing Ring Applications (Manual)</a></li> <li class="toctree-l1"><a class="reference internal" href="distribute_ring2exe.html">Distributing Ring Applications using Ring2EXE</a></li> <li class="toctree-l1"><a class="reference internal" href="ringpm.html">The Ring Package Manager (RingPM)</a></li> <li class="toctree-l1"><a class="reference internal" href="zerolib.html">ZeroLib Functions Reference</a></li> <li class="toctree-l1"><a class="reference internal" href="foxringfuncsdoc.html">FoxRing Functions Reference</a></li> <li class="toctree-l1"><a class="reference internal" href="bignumber.html">BigNumber Functions Reference</a></li> <li class="toctree-l1"><a class="reference internal" href="libcurl.html">Using RingLibCurl</a></li> <li class="toctree-l1"><a class="reference internal" href="ringlibcurlfuncsdoc.html">RingLibCurl Functions Reference</a></li> <li class="toctree-l1"><a class="reference internal" href="socket.html">Using RingSockets</a></li> <li class="toctree-l1"><a class="reference internal" href="threads.html">Using RingThreads</a></li> <li class="toctree-l1"><a class="reference internal" href="libui.html">Using RingLibui</a></li> <li class="toctree-l1"><a class="reference internal" href="ringzip.html">Using RingZip</a></li> <li class="toctree-l1"><a class="reference internal" href="ringlibzipfuncsdoc.html">RingLibZip Functions Reference</a></li> <li class="toctree-l1"><a class="reference internal" href="ringmurmurhashfuncsdoc.html">RingMurmurHash Functions Reference</a></li> <li class="toctree-l1"><a class="reference internal" href="ringconsolecolorsfuncsdoc.html">RingConsoleColors Functions Reference</a></li> <li class="toctree-l1"><a class="reference internal" href="ringallegrofuncsdoc.html">RingAllegro Functions Reference</a></li> <li class="toctree-l1"><a class="reference internal" href="libsdl.html">Using RingLibSDL</a></li> <li class="toctree-l1"><a class="reference internal" href="ringlibsdlfuncsdoc.html">RingLibSDL Functions Reference</a></li> <li class="toctree-l1"><a class="reference internal" href="libuv.html">Using Ringlibuv</a></li> <li class="toctree-l1"><a class="reference internal" href="ringlibuvfuncsdoc.html">RingLibuv Functions Reference</a></li> <li class="toctree-l1"><a class="reference internal" href="ringfreeglutfuncsdoc.html">RingFreeGLUT Functions Reference</a></li> <li class="toctree-l1"><a class="reference internal" href="ringstbimage.html">RingStbImage Functions Reference</a></li> <li class="toctree-l1"><a class="reference internal" href="ringopengl32funcsdoc.html">RingOpenGL (OpenGL 3.2) Functions Reference</a></li> <li class="toctree-l1"><a class="reference internal" href="qtclassesdoc.html">RingQt Classes and Methods Reference</a></li> <li class="toctree-l1"><a class="reference internal" href="lowlevel.html">Low Level Functions</a></li> <li class="toctree-l1"><a class="reference internal" href="extension_tutorial.html">Tutorial: Ring Extensions in C/C++</a></li> <li class="toctree-l1"><a class="reference internal" href="extension.html">Extension using the C/C++ languages</a></li> <li class="toctree-l1"><a class="reference internal" href="embedding.html">Embedding Ring Language in C/C++ Programs</a></li> <li class="toctree-l1"><a class="reference internal" href="codegenerator.html">Code Generator for wrapping C/C++ Libraries</a></li> <li class="toctree-l1"><a class="reference internal" href="ringbeep.html">Create your first extension using the Code Generator</a></li> <li class="toctree-l1"><a class="reference internal" href="languagedesign.html">Release Notes: Version 1.0</a></li> <li class="toctree-l1"><a class="reference internal" href="whatisnew.html">Release Notes: Version 1.1</a></li> <li class="toctree-l1"><a class="reference internal" href="whatisnew2.html">Release Notes: Version 1.2</a></li> <li class="toctree-l1"><a class="reference internal" href="whatisnew3.html">Release Notes: Version 1.3</a></li> <li class="toctree-l1"><a class="reference internal" href="whatisnew4.html">Release Notes: Version 1.4</a></li> <li class="toctree-l1"><a class="reference internal" href="whatisnew5.html">Release Notes: Version 1.5</a></li> <li class="toctree-l1"><a class="reference internal" href="whatisnew6.html">Release Notes: Version 1.6</a></li> <li class="toctree-l1"><a class="reference internal" href="whatisnew7.html">Release Notes: Version 1.7</a></li> <li class="toctree-l1"><a class="reference internal" href="whatisnew8.html">Release Notes: Version 1.8</a></li> <li class="toctree-l1"><a class="reference internal" href="whatisnew9.html">Release Notes: Version 1.9</a></li> <li class="toctree-l1"><a class="reference internal" href="whatisnew10.html">Release Notes: Version 1.10</a></li> <li class="toctree-l1"><a class="reference internal" href="whatisnew11.html">Release Notes: Version 1.11</a></li> <li class="toctree-l1"><a class="reference internal" href="whatisnew12.html">Release Notes: Version 1.12</a></li> <li class="toctree-l1"><a class="reference internal" href="whatisnew13.html">Release Notes: Version 1.13</a></li> <li class="toctree-l1"><a class="reference internal" href="whatisnew14.html">Release Notes: Version 1.14</a></li> <li class="toctree-l1"><a class="reference internal" href="codeeditors.html">Using Other Code Editors</a></li> <li class="toctree-l1"><a class="reference internal" href="faq.html">Frequently Asked Questions (FAQ)</a></li> <li class="toctree-l1"><a class="reference internal" href="sourcecode.html">How to Compile Ring From Source Code?</a></li> <li class="toctree-l1"><a class="reference internal" href="contribute.html">How to contribute?</a></li> <li class="toctree-l1"><a class="reference internal" href="reference.html">Language Specification</a></li> <li class="toctree-l1"><a class="reference internal" href="resources.html">Resources</a></li> </ul> </div> </div> </nav> <section data-toggle="wy-nav-shift" class="wy-nav-content-wrap"> <nav class="wy-nav-top" aria-label="top navigation"> <i data-toggle="wy-nav-top" class="fa fa-bars"></i> <a href="index.html">Ring</a> </nav> <div class="wy-nav-content"> <div class="rst-content"> <div role="navigation" aria-label="breadcrumbs navigation"> <ul class="wy-breadcrumbs"> <li><a href="index.html" class="icon icon-home"></a> »</li> <li>Security and Internet Functions</li> <li class="wy-breadcrumbs-aside"> </li> </ul> <hr/> </div> <div role="main" class="document" itemscope="itemscope" itemtype="http://schema.org/Article"> <div itemprop="articleBody"> <div class="section" id="security-and-internet-functions"> <span id="index-0"></span><h1>Security and Internet Functions<a class="headerlink" href="#security-and-internet-functions" title="Permalink to this headline">¶</a></h1> <p>This chapter contains the security and internet functions provided by the Ring programming language for Hashing, Encryption & Decryption.</p> <p>Before using the next functions load the openssllib.ring library</p> <div class="highlight-ring notranslate"><div class="highlight"><pre><span></span><span class="k">load</span> <span class="s">"openssllib.ring"</span> <span class="c"># Use OpenSSL functions</span> </pre></div> </div> <ul class="simple"> <li><p>MD5()</p></li> <li><p>SHA1()</p></li> <li><p>SHA256()</p></li> <li><p>SHA512()</p></li> <li><p>SHA384()</p></li> <li><p>SHA224()</p></li> <li><p>Encrypt()</p></li> <li><p>Decrypt()</p></li> <li><p>Randbytes()</p></li> <li><p>MD5Init(), MD5Update(), MD5Final()</p></li> <li><p>SHA1Init(), SHA1Update(), SHA1Final()</p></li> <li><p>SHA256Init(), SHA256Update(), SHA256Final()</p></li> <li><p>SHA512Init(), SHA512Update(), SHA512Final()</p></li> <li><p>SHA384Init(), SHA384Update(), SHA384Final()</p></li> <li><p>SHA224Init(), SHA224Update(), SHA224Final()</p></li> </ul> <p>Before using the next functions load the internetlib.ring library</p> <div class="highlight-ring notranslate"><div class="highlight"><pre><span></span><span class="k">load</span> <span class="s">"internetlib.ring"</span> <span class="c"># Use the Internet functions</span> </pre></div> </div> <ul class="simple"> <li><p>Download()</p></li> <li><p>SendEmail()</p></li> </ul> <div class="section" id="md5-function"> <span id="index-1"></span><h2>MD5() Function<a class="headerlink" href="#md5-function" title="Permalink to this headline">¶</a></h2> <p>We can calculate the MD5 hash using the MD5() Function</p> <p>Syntax:</p> <div class="highlight-ring notranslate"><div class="highlight"><pre><span></span><span class="n">MD5</span><span class="p">(</span><span class="n">cString</span><span class="p">)</span> <span class="o">---></span> <span class="kt">String</span> <span class="n">contains</span> <span class="n">the</span> <span class="n">MD5</span> <span class="n">hash</span> <span class="n">of</span> <span class="n">the</span> <span class="kt">string</span> <span class="n">cString</span> </pre></div> </div> <p>Example:</p> <div class="highlight-ring notranslate"><div class="highlight"><pre><span></span><span class="k">see</span> <span class="s">"md5('happy') = "</span> <span class="o">+</span> <span class="n">md5</span><span class="p">(</span><span class="s">"happy"</span><span class="p">)</span> <span class="o">+</span> <span class="n">nl</span> <span class="o">+</span> <span class="s">"md5('Hello') = "</span> <span class="o">+</span> <span class="n">md5</span><span class="p">(</span><span class="s">"Hello"</span><span class="p">)</span> <span class="o">+</span> <span class="n">nl</span> </pre></div> </div> <p>Output:</p> <div class="highlight-ring notranslate"><div class="highlight"><pre><span></span>md5('happy') = 56ab24c15b72a457069c5ea42fcfc640 md5('Hello') = 8b1a9953c4611296a827abf8c47804d7 </pre></div> </div> </div> <div class="section" id="sha1-function"> <span id="index-2"></span><h2>SHA1() Function<a class="headerlink" href="#sha1-function" title="Permalink to this headline">¶</a></h2> <p>We can calculate the SHA1 hash using the SHA1() Function</p> <p>Syntax:</p> <div class="highlight-ring notranslate"><div class="highlight"><pre><span></span><span class="n">SHA1</span><span class="p">(</span><span class="n">cString</span><span class="p">)</span> <span class="o">---></span> <span class="kt">String</span> <span class="n">contains</span> <span class="n">the</span> <span class="n">SHA1</span> <span class="n">hash</span> <span class="n">of</span> <span class="n">the</span> <span class="kt">string</span> <span class="n">cString</span> </pre></div> </div> <p>Example:</p> <div class="highlight-ring notranslate"><div class="highlight"><pre><span></span><span class="k">see</span> <span class="s">"sha1('hello') : "</span> <span class="o">+</span> <span class="n">sha1</span><span class="p">(</span><span class="s">"hello"</span><span class="p">)</span> <span class="o">+</span> <span class="n">nl</span> <span class="o">+</span> <span class="s">"sha1('apple') : "</span> <span class="o">+</span> <span class="n">sha1</span><span class="p">(</span><span class="s">"apple"</span><span class="p">)</span> <span class="o">+</span> <span class="n">nl</span> </pre></div> </div> <p>Output:</p> <div class="highlight-ring notranslate"><div class="highlight"><pre><span></span><span class="n">sha1</span><span class="p">(</span><span class="sc">'hello'</span><span class="p">)</span> <span class="p">:</span> <span class="n">aaf4c61ddcc5e8a2dabede0f3b482cd9aea9434d</span> <span class="n">sha1</span><span class="p">(</span><span class="sc">'apple'</span><span class="p">)</span> <span class="p">:</span> <span class="n">d0be2dc421be4fcd0172e5afceea3970e2f3d940</span> </pre></div> </div> </div> <div class="section" id="sha256-function"> <span id="index-3"></span><h2>SHA256() Function<a class="headerlink" href="#sha256-function" title="Permalink to this headline">¶</a></h2> <p>We can calculate the SHA256 hash using the SHA256() Function</p> <p>Syntax:</p> <div class="highlight-ring notranslate"><div class="highlight"><pre><span></span><span class="n">SHA256</span><span class="p">(</span><span class="n">cString</span><span class="p">)</span> <span class="o">---></span> <span class="kt">String</span> <span class="n">contains</span> <span class="n">the</span> <span class="n">SHA256</span> <span class="n">hash</span> <span class="n">of</span> <span class="n">the</span> <span class="kt">string</span> <span class="n">cString</span> </pre></div> </div> <p>Example:</p> <div class="highlight-ring notranslate"><div class="highlight"><pre><span></span><span class="k">see</span> <span class="s">"sha256('hello') : "</span> <span class="o">+</span> <span class="n">sha256</span><span class="p">(</span><span class="s">"hello"</span><span class="p">)</span> <span class="o">+</span> <span class="n">nl</span> <span class="o">+</span> <span class="s">"sha256('apple') : "</span> <span class="o">+</span> <span class="n">sha256</span><span class="p">(</span><span class="s">"apple"</span><span class="p">)</span> <span class="o">+</span> <span class="n">nl</span> </pre></div> </div> <p>Output:</p> <div class="highlight-ring notranslate"><div class="highlight"><pre><span></span>sha256('hello') : 2cf24dba5fb0a30e26e83b2ac5b9e29e1b161e5c1fa7425e73043362938b9824 sha256('apple') : 3a7bd3e2360a3d29eea436fcfb7e44c735d117c42d1c1835420b6b9942dd4f1b </pre></div> </div> </div> <div class="section" id="sha512-function"> <span id="index-4"></span><h2>SHA512() Function<a class="headerlink" href="#sha512-function" title="Permalink to this headline">¶</a></h2> <p>We can calculate the SHA512 hash using the SHA512() Function</p> <p>Syntax:</p> <div class="highlight-ring notranslate"><div class="highlight"><pre><span></span><span class="n">SHA512</span><span class="p">(</span><span class="n">cString</span><span class="p">)</span> <span class="o">---></span> <span class="kt">String</span> <span class="n">contains</span> <span class="n">the</span> <span class="n">SHA512</span> <span class="n">hash</span> <span class="n">of</span> <span class="n">the</span> <span class="kt">string</span> <span class="n">cString</span> </pre></div> </div> <p>Example:</p> <div class="highlight-ring notranslate"><div class="highlight"><pre><span></span><span class="k">see</span> <span class="s">"sha512('hello') : "</span> <span class="o">+</span> <span class="n">sha512</span><span class="p">(</span><span class="s">"hello"</span><span class="p">)</span> <span class="o">+</span> <span class="n">nl</span> <span class="o">+</span> <span class="s">"sha512('apple') : "</span> <span class="o">+</span> <span class="n">sha512</span><span class="p">(</span><span class="s">"apple"</span><span class="p">)</span> <span class="o">+</span> <span class="n">nl</span> <span class="o">+</span> <span class="s">"sha512('hello world') : "</span> <span class="o">+</span> <span class="n">sha512</span><span class="p">(</span><span class="s">"hello world"</span><span class="p">)</span> <span class="o">+</span> <span class="n">nl</span> </pre></div> </div> <p>Output:</p> <div class="highlight-ring notranslate"><div class="highlight"><pre><span></span>sha512('hello') : 9b71d224bd62f3785d96d46ad3ea3d73319bfbc2890caadae2dff72519673c a72323c3d99ba5c11d7c7acc6e14b8c5da0c4663475c2e5c3adef46f73bcdec043 sha512('apple') : 844d8779103b94c18f4aa4cc0c3b4474058580a991fba85d3ca698a0bc9e52 c5940feb7a65a3a290e17e6b23ee943ecc4f73e7490327245b4fe5d5efb590feb2 sha512('hello world') : 309ecc489c12d6eb4cc40f50c902f2b4d0ed77ee511a7c7a9bcd3ca8 6d4cd86f989dd35bc5ff499670da34255b45b0cfd830e81f605dcf7dc5542e93ae9cd76f </pre></div> </div> </div> <div class="section" id="sha384-function"> <span id="index-5"></span><h2>SHA384() Function<a class="headerlink" href="#sha384-function" title="Permalink to this headline">¶</a></h2> <p>We can calculate the SHA384 hash using the SHA384() Function</p> <p>Syntax:</p> <div class="highlight-ring notranslate"><div class="highlight"><pre><span></span><span class="n">SHA384</span><span class="p">(</span><span class="n">cString</span><span class="p">)</span> <span class="o">---></span> <span class="kt">String</span> <span class="n">contains</span> <span class="n">the</span> <span class="n">SHA384</span> <span class="n">hash</span> <span class="n">of</span> <span class="n">the</span> <span class="kt">string</span> <span class="n">cString</span> </pre></div> </div> <p>Example:</p> <div class="highlight-ring notranslate"><div class="highlight"><pre><span></span><span class="k">see</span> <span class="s">"sha384('hello') : "</span> <span class="o">+</span> <span class="n">sha384</span><span class="p">(</span><span class="s">"hello"</span><span class="p">)</span> <span class="o">+</span> <span class="n">nl</span> <span class="o">+</span> <span class="s">"sha384('apple') : "</span> <span class="o">+</span> <span class="n">sha384</span><span class="p">(</span><span class="s">"apple"</span><span class="p">)</span> <span class="o">+</span> <span class="n">nl</span> <span class="o">+</span> <span class="s">"sha384('hello world') : "</span> <span class="o">+</span> <span class="n">sha384</span><span class="p">(</span><span class="s">"hello world"</span><span class="p">)</span> <span class="o">+</span> <span class="n">nl</span> </pre></div> </div> <p>Output:</p> <div class="highlight-ring notranslate"><div class="highlight"><pre><span></span>sha384('hello') : 59e1748777448c69de6b800d7a33bbfb9ff1b463e44354c3553bcdb9c666fa 90125a3c79f90397bdf5f6a13de828684f sha384('apple') : 3d8786fcb588c93348756c6429717dc6c374a14f7029362281a3b21dc10250 ddf0d0578052749822eb08bc0dc1e68b0f sha384('hello world') : fdbd8e75a67f29f701a4e040385e2e23986303ea10239211af907fcb b83578b3e417cb71ce646efd0819dd8c088de1bd </pre></div> </div> </div> <div class="section" id="sha224-function"> <span id="index-6"></span><h2>SHA224() Function<a class="headerlink" href="#sha224-function" title="Permalink to this headline">¶</a></h2> <p>We can calculate the SHA224 hash using the SHA224() Function</p> <p>Syntax:</p> <div class="highlight-ring notranslate"><div class="highlight"><pre><span></span><span class="n">SHA224</span><span class="p">(</span><span class="n">cString</span><span class="p">)</span> <span class="o">---></span> <span class="kt">String</span> <span class="n">contains</span> <span class="n">the</span> <span class="n">SHA224</span> <span class="n">hash</span> <span class="n">of</span> <span class="n">the</span> <span class="kt">string</span> <span class="n">cString</span> </pre></div> </div> <p>Example:</p> <div class="highlight-ring notranslate"><div class="highlight"><pre><span></span><span class="k">see</span> <span class="s">"sha224('hello') : "</span> <span class="o">+</span> <span class="n">sha224</span><span class="p">(</span><span class="s">"hello"</span><span class="p">)</span> <span class="o">+</span> <span class="n">nl</span> <span class="o">+</span> <span class="s">"sha224('apple') : "</span> <span class="o">+</span> <span class="n">sha224</span><span class="p">(</span><span class="s">"apple"</span><span class="p">)</span> <span class="o">+</span> <span class="n">nl</span> <span class="o">+</span> <span class="s">"sha224('hello world') : "</span> <span class="o">+</span> <span class="n">sha224</span><span class="p">(</span><span class="s">"hello world"</span><span class="p">)</span> <span class="o">+</span> <span class="n">nl</span> </pre></div> </div> <p>Output:</p> <div class="highlight-ring notranslate"><div class="highlight"><pre><span></span>sha224('hello') : ea09ae9cc6768c50fcee903ed054556e5bfc8347907f12598aa24193 sha224('apple') : b7bbfdf1a1012999b3c466fdeb906a629caa5e3e022428d1eb702281 sha224('hello world') : 2f05477fc24bb4faefd86517156dafdecec45b8ad3cf2522a563582b </pre></div> </div> </div> <div class="section" id="encrypt-function"> <span id="index-7"></span><h2>Encrypt() Function<a class="headerlink" href="#encrypt-function" title="Permalink to this headline">¶</a></h2> <p>We can use the Encrypt() function to encrypts the data using the Blowfish algorithm.</p> <p>Syntax:</p> <div class="highlight-ring notranslate"><div class="highlight"><pre><span></span><span class="n">Encrypt</span><span class="p">(</span><span class="n">cString</span><span class="p">,</span> <span class="n">cKey</span><span class="p">,</span> <span class="n">cIV</span><span class="p">)</span> <span class="o">---></span> <span class="n">Encrypted</span> <span class="kt">string</span> </pre></div> </div> </div> <div class="section" id="decrypt-function"> <span id="index-8"></span><h2>Decrypt() Function<a class="headerlink" href="#decrypt-function" title="Permalink to this headline">¶</a></h2> <p>We can use the Decrypt() function to decrypt the data encrypted using the Encrypt() function.</p> <p>Syntax:</p> <div class="highlight-ring notranslate"><div class="highlight"><pre><span></span><span class="n">Decrypt</span><span class="p">(</span><span class="n">cCipher</span><span class="p">,</span> <span class="n">cKey</span><span class="p">,</span> <span class="n">cIV</span><span class="p">)</span> <span class="o">---></span> <span class="n">Decrypted</span> <span class="kt">string</span> </pre></div> </div> </div> <div class="section" id="encryption-and-decryption-example"> <span id="index-9"></span><h2>Encryption and Decryption Example<a class="headerlink" href="#encryption-and-decryption-example" title="Permalink to this headline">¶</a></h2> <p>The next example demonstrates how to use the Encrypt() and Decrypt() functions.</p> <p>These functions use the Blowfish algorithm.</p> <div class="highlight-ring notranslate"><div class="highlight"><pre><span></span><span class="k">See</span> <span class="s">"Enter a string : "</span> <span class="k">give</span> <span class="n">cStr</span> <span class="kt">list</span> <span class="o">=</span> <span class="mi">0</span><span class="p">:</span><span class="mi">15</span> <span class="n">cKey</span><span class="o">=</span><span class="s">""</span> <span class="k">for</span> <span class="n">x</span> <span class="k">in</span> <span class="kt">list</span> <span class="n">cKey</span> <span class="o">+=</span> <span class="n">char</span><span class="p">(</span><span class="n">x</span><span class="p">)</span> <span class="k">next</span> <span class="kt">list</span> <span class="o">=</span> <span class="mi">1</span><span class="p">:</span><span class="mi">8</span> <span class="n">cIV</span> <span class="o">=</span> <span class="s">""</span> <span class="k">for</span> <span class="n">x</span> <span class="k">in</span> <span class="kt">list</span> <span class="n">cIV</span> <span class="o">+=</span> <span class="n">char</span><span class="p">(</span><span class="n">x</span><span class="p">)</span> <span class="k">next</span> <span class="n">cStr</span> <span class="o">=</span> <span class="n">Encrypt</span><span class="p">(</span><span class="n">cStr</span><span class="p">,</span><span class="n">cKey</span><span class="p">,</span><span class="n">cIV</span><span class="p">)</span> <span class="k">See</span> <span class="s">"Cipher Text : "</span> <span class="o">+</span> <span class="n">cStr</span> <span class="o">+</span> <span class="n">nl</span> <span class="o">+</span> <span class="s">"Plain Text : "</span> <span class="o">+</span> <span class="n">Decrypt</span><span class="p">(</span><span class="n">cStr</span><span class="p">,</span><span class="n">cKey</span><span class="p">,</span><span class="n">cIV</span><span class="p">)</span> <span class="o">+</span> <span class="n">nl</span> </pre></div> </div> <p>We can write the same example using normal for loop</p> <div class="highlight-ring notranslate"><div class="highlight"><pre><span></span><span class="k">See</span> <span class="s">"Enter a string : "</span> <span class="k">give</span> <span class="n">cStr</span> <span class="n">cKey</span><span class="o">=</span><span class="s">""</span> <span class="c"># 16 bytes</span> <span class="k">for</span> <span class="n">x</span> <span class="o">=</span> <span class="mi">0</span> <span class="k">to</span> <span class="mi">15</span> <span class="n">cKey</span> <span class="o">+=</span> <span class="n">char</span><span class="p">(</span><span class="n">x</span><span class="p">)</span> <span class="k">next</span> <span class="n">cIV</span> <span class="o">=</span> <span class="s">""</span> <span class="k">for</span> <span class="n">x</span> <span class="o">=</span> <span class="mi">1</span> <span class="k">to</span> <span class="mi">8</span> <span class="n">cIV</span> <span class="o">+=</span> <span class="n">char</span><span class="p">(</span><span class="n">x</span><span class="p">)</span> <span class="k">next</span> <span class="n">cStr</span> <span class="o">=</span> <span class="n">Encrypt</span><span class="p">(</span><span class="n">cStr</span><span class="p">,</span><span class="n">cKey</span><span class="p">,</span><span class="n">cIV</span><span class="p">)</span> <span class="k">See</span> <span class="s">"Cipher Text : "</span> <span class="o">+</span> <span class="n">cStr</span> <span class="o">+</span> <span class="n">nl</span> <span class="o">+</span> <span class="s">"Plain Text : "</span> <span class="o">+</span> <span class="n">Decrypt</span><span class="p">(</span><span class="n">cStr</span><span class="p">,</span><span class="n">cKey</span><span class="p">,</span><span class="n">cIV</span><span class="p">)</span> <span class="o">+</span> <span class="n">nl</span> </pre></div> </div> <p>Also we can write the password and the IV directly using strings</p> <div class="highlight-ring notranslate"><div class="highlight"><pre><span></span><span class="k">See</span> <span class="s">"Enter a string : "</span> <span class="k">give</span> <span class="n">cStr</span> <span class="c"># Note: Don't use simple password in real applications!</span> <span class="n">cKey</span> <span class="o">=</span> <span class="s">"1234567890@#$%^&"</span> <span class="n">cIV</span> <span class="o">=</span> <span class="s">"87654321"</span> <span class="n">cStr</span> <span class="o">=</span> <span class="n">Encrypt</span><span class="p">(</span><span class="n">cStr</span><span class="p">,</span><span class="n">cKey</span><span class="p">,</span><span class="n">cIV</span><span class="p">)</span> <span class="k">See</span> <span class="s">"Cipher Text : "</span> <span class="o">+</span> <span class="n">cStr</span> <span class="o">+</span> <span class="n">nl</span> <span class="o">+</span> <span class="s">"Plain Text : "</span> <span class="o">+</span> <span class="n">Decrypt</span><span class="p">(</span><span class="n">cStr</span><span class="p">,</span><span class="n">cKey</span><span class="p">,</span><span class="n">cIV</span><span class="p">)</span> <span class="o">+</span> <span class="n">nl</span> </pre></div> </div> </div> <div class="section" id="file-hash"> <span id="index-10"></span><h2>File Hash<a class="headerlink" href="#file-hash" title="Permalink to this headline">¶</a></h2> <p>The next example demonstrates how to calculate the hash functions for files</p> <div class="highlight-ring notranslate"><div class="highlight"><pre><span></span><span class="n">cStr</span> <span class="o">=</span> <span class="n">read</span><span class="p">(</span><span class="s">"myapp.exe"</span><span class="p">)</span> <span class="k">see</span> <span class="s">"Size : "</span> <span class="o">+</span> <span class="n">len</span><span class="p">(</span><span class="n">cStr</span><span class="p">)</span> <span class="o">+</span> <span class="n">nl</span> <span class="o">+</span> <span class="s">"md5 : "</span> <span class="o">+</span> <span class="n">md5</span><span class="p">(</span><span class="n">cStr</span><span class="p">)</span> <span class="o">+</span> <span class="n">nl</span> <span class="o">+</span> <span class="s">"sha1 : "</span> <span class="o">+</span> <span class="n">sha1</span><span class="p">(</span><span class="n">cStr</span><span class="p">)</span> <span class="o">+</span> <span class="n">nl</span> <span class="o">+</span> <span class="s">"sha256 : "</span> <span class="o">+</span> <span class="n">sha256</span><span class="p">(</span><span class="n">cStr</span><span class="p">)</span> <span class="o">+</span> <span class="n">nl</span> <span class="o">+</span> <span class="s">"sha224 : "</span> <span class="o">+</span> <span class="n">sha224</span><span class="p">(</span><span class="n">cStr</span><span class="p">)</span> <span class="o">+</span> <span class="n">nl</span> <span class="o">+</span> <span class="s">"sha384 : "</span> <span class="o">+</span> <span class="n">sha384</span><span class="p">(</span><span class="n">cStr</span><span class="p">)</span> <span class="o">+</span> <span class="n">nl</span> <span class="o">+</span> <span class="s">"sha512 : "</span> <span class="o">+</span> <span class="n">sha512</span><span class="p">(</span><span class="n">cStr</span><span class="p">)</span> <span class="o">+</span> <span class="n">nl</span> </pre></div> </div> <p>Output:</p> <div class="highlight-ring notranslate"><div class="highlight"><pre><span></span>Size : 58079876 md5 : 762eee15d8d2fd73b71ea52538b28667 sha1 : 9212c0c7258bad89a62bd239e1358a9276a9d070 sha256 : 7d6724e69b6c553da749ba31b6185dddc965129b64d9e9bf3de88f67df3b1cdc sha224 : 5a9c8a7d662bce4f880ba94f90a79362b672528b9efd5abc718c7a3d sha384 : 18e23f973abedbeb3981c423f12aeadecf96f9c6fb28aeabe3be4c484f8540afcc3861b b370ce2b59cf3c99c130b856b sha512 : da3d5e997d06f8b2a7a9964b77f7d82eedb76b245c611082c1639f83f51d83880bcd08f cd53dcab1167bdca0b82fec5071971ac17c76479d76985ced4ab0d18e </pre></div> </div> </div> <div class="section" id="randbytes-function"> <span id="index-11"></span><h2>Randbytes() Function<a class="headerlink" href="#randbytes-function" title="Permalink to this headline">¶</a></h2> <p>We can generate a string of pseudo-random bytes using the Randbytes() function.</p> <p>Syntax:</p> <div class="highlight-ring notranslate"><div class="highlight"><pre><span></span><span class="n">Randbytes</span><span class="p">(</span><span class="n">nSize</span><span class="p">)</span> <span class="o">---></span> <span class="kt">String</span> <span class="n">contains</span> <span class="n">random</span> <span class="n">bytes</span> <span class="p">(</span><span class="n">bytes</span> <span class="n">count</span> <span class="o">=</span> <span class="n">nSize</span><span class="p">)</span> </pre></div> </div> <p>Example:</p> <div class="highlight-ring notranslate"><div class="highlight"><pre><span></span><span class="n">salt</span> <span class="o">=</span> <span class="n">randbytes</span><span class="p">(</span><span class="mi">32</span><span class="p">)</span> <span class="n">password</span> <span class="o">=</span> <span class="s">"SecretPassWord@$%123"</span> <span class="k">see</span> <span class="n">salt</span> <span class="o">+</span> <span class="n">nl</span> <span class="k">see</span> <span class="n">sha256</span><span class="p">(</span><span class="s">"test"</span> <span class="o">+</span> <span class="n">salt</span><span class="p">)</span> <span class="o">+</span> <span class="n">nl</span> </pre></div> </div> </div> <div class="section" id="large-files-hash"> <span id="index-12"></span><h2>Large Files Hash<a class="headerlink" href="#large-files-hash" title="Permalink to this headline">¶</a></h2> <p>These functions compute the hash of large files/data without the need to load all of the content in a single string.</p> <div class="highlight-none notranslate"><div class="highlight"><pre><span></span>md5init() -> MD5_CTX md5update (MD5_CTX, string) -> 1 for success or 0 for failure md5final (MD5_CTX) -> string sha1init() -> SHA_CTX sha1update (SHA_CTX, string) -> 1 for success or 0 for failure sha1final (SHA_CTX) -> string sha224init() -> SHA224_CTX sha224update (SHA224_CTX, string) -> 1 for success or 0 for failure sha224final (SHA224_CTX) -> string sha256init() -> SHA256_CTX sha256update (SHA256_CTX, string) -> 1 for success or 0 for failure sha256final (SHA256_CTX) -> string sha384init() -> SHA384_CTX sha384update (SHA384_CTX, string) -> 1 for success or 0 for failure sha384final (SHA384_CTX) -> string sha512init() -> SHA512_CTX sha512update (SHA512_CTX, string) -> 1 for success or 0 for failure sha512final (SHA512_CTX) -> string </pre></div> </div> </div> <div class="section" id="download-function"> <span id="index-13"></span><h2>Download() Function<a class="headerlink" href="#download-function" title="Permalink to this headline">¶</a></h2> <p>Syntax:</p> <div class="highlight-ring notranslate"><div class="highlight"><pre><span></span><span class="n">Download</span><span class="p">(</span><span class="n">cURL</span><span class="p">)</span> <span class="o">---></span> <span class="kt">String</span> <span class="n">contains</span> <span class="n">the</span> <span class="n">server</span> <span class="n">response</span> </pre></div> </div> <p>Example:</p> <div class="highlight-ring notranslate"><div class="highlight"><pre><span></span><span class="n">cStr</span><span class="o">=</span> <span class="n">download</span><span class="p">(</span><span class="s">"http://doublesvsoop.sourceforge.net/"</span><span class="p">)</span> <span class="k">see</span> <span class="n">cStr</span> <span class="n">write</span><span class="p">(</span><span class="s">"download.txt"</span><span class="p">,</span><span class="n">cStr</span><span class="p">)</span> </pre></div> </div> </div> <div class="section" id="sendemail-function"> <span id="index-14"></span><h2>SendEmail() Function<a class="headerlink" href="#sendemail-function" title="Permalink to this headline">¶</a></h2> <p>Syntax:</p> <div class="highlight-ring notranslate"><div class="highlight"><pre><span></span><span class="n">SendEmail</span><span class="p">(</span><span class="n">cSMTPServer</span><span class="p">,</span><span class="n">cEmail</span><span class="p">,</span><span class="n">cPassword</span><span class="p">,</span><span class="n">cSender</span><span class="p">,</span><span class="n">cReceiver</span><span class="p">,</span><span class="n">cCC</span><span class="p">,</span><span class="n">cTitle</span><span class="p">,</span><span class="n">cContent</span><span class="p">)</span> </pre></div> </div> <p>Example:</p> <div class="highlight-ring notranslate"><div class="highlight"><pre><span></span><span class="k">See</span> <span class="s">"Send email..."</span> <span class="o">+</span> <span class="n">nl</span> <span class="n">sendemail</span><span class="p">(</span><span class="s">"smtp://smtp.gmail.com:587"</span><span class="p">,</span> <span class="s">"email@gmail.com"</span><span class="p">,</span> <span class="s">"password"</span><span class="p">,</span> <span class="s">"email@gmail.com"</span><span class="p">,</span> <span class="s">"somebody@yahoo.com"</span><span class="p">,</span> <span class="s">"somebodyelse@yahoo.com"</span><span class="p">,</span> <span class="s">"Sending email from Ring"</span><span class="p">,</span> <span class="s">"Hello</span> <span class="n">How</span> <span class="n">are</span> <span class="n">you</span><span class="o">?</span> <span class="n">Are</span> <span class="n">you</span> <span class="n">fine</span><span class="o">?</span> <span class="n">Thank</span> <span class="n">you</span><span class="o">!</span> <span class="n">Greetings</span><span class="p">,</span> <span class="s">Mahmoud")</span> <span class="k">see</span> <span class="s">"Done.."</span> <span class="o">+</span> <span class="n">nl</span> </pre></div> </div> </div> </div> </div> </div> <footer> <div class="rst-footer-buttons" role="navigation" aria-label="footer navigation"> <a href="oop.html" class="btn btn-neutral float-right" title="Object Oriented Programming (OOP)" accesskey="n" rel="next">Next <span class="fa fa-arrow-circle-right"></span></a> <a href="postgresql.html" class="btn btn-neutral float-left" title="PostgreSQL Functions" accesskey="p" rel="prev"><span class="fa fa-arrow-circle-left"></span> Previous</a> </div> <hr/> <div role="contentinfo"> <p> © Copyright 2016-2021, Ring Team </p> </div> Built with <a href="http://sphinx-doc.org/">Sphinx</a> using a <a href="https://github.com/rtfd/sphinx_rtd_theme">theme</a> provided by <a href="https://readthedocs.org">Read the Docs</a>. </footer> </div> </div> </section> </div> <script type="text/javascript"> jQuery(function () { SphinxRtdTheme.Navigation.enable(false); }); </script> </body> </html>