0% found this document useful (0 votes)
56 views2 pages

WiFi - Connection and Cryptography

The document shows code for connecting an ESP8266 WiFi module to a network and printing the IP address. It also contains a C# class for encrypting and decrypting strings using AES encryption.

Uploaded by

Ariance Project
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
56 views2 pages

WiFi - Connection and Cryptography

The document shows code for connecting an ESP8266 WiFi module to a network and printing the IP address. It also contains a C# class for encrypting and decrypting strings using AES encryption.

Uploaded by

Ariance Project
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 2

#include <ESP8266WiFi.

h> // Include the Wi-Fi library

const char* ssid = "192.168.100.5"; // The SSID (name) of the Wi-Fi


network you want to connect to
const char* password = "ariance@2"; // The password of the Wi-Fi
network

void setup()
{
Serial.begin(115200); // Start the Serial communication to send messages
to the computer
delay(10);
Serial.println('\n');

WiFi.begin(ssid, password); // Connect to the network


Serial.print("Connecting to ");
Serial.print(ssid);
Serial.println(" ...");

int i = 0;
while (WiFi.status() != WL_CONNECTED)
{ // Wait for the Wi-Fi to connect
delay(1000);
Serial.print(++i);
Serial.print(' ');
}

Serial.println('\n');
Serial.println("Connection established!");
Serial.print("IP address:\t");
Serial.println(WiFi.localIP()); // Send the IP address of the ESP8266 to
the computer
}

void loop()
{
}

using System.IO;
using System.Text;
using System.Security.Cryptography;
using System;

public static class EncryptionHelper


{
public static string Encrypt(string clearText)
{
string EncryptionKey = "Anilkey123";
byte[] clearBytes = Encoding.Unicode.GetBytes(clearText);
using (Aes encryptor = Aes.Create())
{
Rfc2898DeriveBytes pdb = new Rfc2898DeriveBytes(EncryptionKey, new byte[] {
0x49, 0x76, 0x61, 0x6e, 0x20,0x4d, 0x65, 0x64, 0x76, 0x65, 0x64, 0x65, 0x76 });
encryptor.Key = pdb.GetBytes(32);
encryptor.IV = pdb.GetBytes(16);
using (MemoryStream ms = new MemoryStream())
{
using (CryptoStream cs = new CryptoStream(ms,
encryptor.CreateEncryptor(), CryptoStreamMode.Write))
{
cs.Write(clearBytes, 0, clearBytes.Length);
cs.Close();
}
clearText = Convert.ToBase64String(ms.ToArray());
}
}
return clearText;
}

public static string Decrypt(string cipherText)


{
string EncryptionKey = " Anilkey123";
cipherText = cipherText.Replace(" ", "+");
byte[] cipherBytes = Convert.FromBase64String(cipherText);
using (Aes encryptor = Aes.Create())
{
Rfc2898DeriveBytes pdb = new Rfc2898DeriveBytes(EncryptionKey, new byte[] {
0x49, 0x76, 0x61, 0x6e, 0x20, 0x4d, 0x65, 0x64, 0x76, 0x65, 0x64, 0x65, 0x76 });
encryptor.Key = pdb.GetBytes(32);
encryptor.IV = pdb.GetBytes(16);
using (MemoryStream ms = new MemoryStream())
{
using (CryptoStream cs = new CryptoStream(ms,
encryptor.CreateDecryptor(), CryptoStreamMode.Write))
{
cs.Write(cipherBytes, 0, cipherBytes.Length);
cs.Close();
}
cipherText = Encoding.Unicode.GetString(ms.ToArray());
}
}
return cipherText;
}
}

You might also like