Skip to content

Commit 221cd7d

Browse files
author
Jayant Kumar Tripathy
committed
Encryption & Decryption using AES Algorithim
0 parents  commit 221cd7d

File tree

348 files changed

+254765
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

348 files changed

+254765
-0
lines changed

Encrypt-JavaScript-Decrypt-Csharp.sln

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
2+
Microsoft Visual Studio Solution File, Format Version 11.00
3+
# Visual Studio 2010
4+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Encrypt-JavaScript-Decrypt-Csharp", "Encrypt-JavaScript-Decrypt-Csharp\Encrypt-JavaScript-Decrypt-Csharp.csproj", "{69D4AE3A-F60D-4399-838A-AAC4AA9D2D51}"
5+
EndProject
6+
Global
7+
GlobalSection(SolutionConfigurationPlatforms) = preSolution
8+
Debug|Any CPU = Debug|Any CPU
9+
Release|Any CPU = Release|Any CPU
10+
EndGlobalSection
11+
GlobalSection(ProjectConfigurationPlatforms) = postSolution
12+
{69D4AE3A-F60D-4399-838A-AAC4AA9D2D51}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
13+
{69D4AE3A-F60D-4399-838A-AAC4AA9D2D51}.Debug|Any CPU.Build.0 = Debug|Any CPU
14+
{69D4AE3A-F60D-4399-838A-AAC4AA9D2D51}.Release|Any CPU.ActiveCfg = Release|Any CPU
15+
{69D4AE3A-F60D-4399-838A-AAC4AA9D2D51}.Release|Any CPU.Build.0 = Release|Any CPU
16+
EndGlobalSection
17+
GlobalSection(SolutionProperties) = preSolution
18+
HideSolutionNode = FALSE
19+
EndGlobalSection
20+
EndGlobal

Encrypt-JavaScript-Decrypt-Csharp.suo

46.5 KB
Binary file not shown.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,135 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Web;
5+
using System.Security.Cryptography;
6+
using System.Text;
7+
using System.IO;
8+
9+
namespace Encrypt_JavaScript_Decrypt_Csharp
10+
{
11+
public class AESEncryption
12+
{
13+
public static string DecryptStringAES(string cipherText)
14+
{
15+
16+
var keybytes = Encoding.UTF8.GetBytes("8080808080808080");
17+
var iv = Encoding.UTF8.GetBytes("8080808080808080");
18+
19+
var encrypted = Convert.FromBase64String(cipherText);
20+
var decriptedFromJavascript = DecryptStringFromBytes(encrypted, keybytes, iv);
21+
return string.Format(decriptedFromJavascript);
22+
}
23+
24+
private static string DecryptStringFromBytes(byte[] cipherText, byte[] key, byte[] iv)
25+
{
26+
// Check arguments.
27+
if (cipherText == null || cipherText.Length <= 0)
28+
{
29+
throw new ArgumentNullException("cipherText");
30+
}
31+
if (key == null || key.Length <= 0)
32+
{
33+
throw new ArgumentNullException("key");
34+
}
35+
if (iv == null || iv.Length <= 0)
36+
{
37+
throw new ArgumentNullException("key");
38+
}
39+
40+
// Declare the string used to hold
41+
// the decrypted text.
42+
string plaintext = null;
43+
44+
// Create an RijndaelManaged object
45+
// with the specified key and IV.
46+
using (var rijAlg = new RijndaelManaged())
47+
{
48+
//Settings
49+
rijAlg.Mode = CipherMode.CBC;
50+
rijAlg.Padding = PaddingMode.PKCS7;
51+
rijAlg.FeedbackSize = 128;
52+
53+
rijAlg.Key = key;
54+
rijAlg.IV = iv;
55+
56+
// Create a decrytor to perform the stream transform.
57+
var decryptor = rijAlg.CreateDecryptor(rijAlg.Key, rijAlg.IV);
58+
try
59+
{
60+
// Create the streams used for decryption.
61+
using (var msDecrypt = new MemoryStream(cipherText))
62+
{
63+
using (var csDecrypt = new CryptoStream(msDecrypt, decryptor, CryptoStreamMode.Read))
64+
{
65+
66+
using (var srDecrypt = new StreamReader(csDecrypt))
67+
{
68+
// Read the decrypted bytes from the decrypting stream
69+
// and place them in a string.
70+
plaintext = srDecrypt.ReadToEnd();
71+
72+
}
73+
74+
}
75+
}
76+
}
77+
catch
78+
{
79+
plaintext = "keyError";
80+
}
81+
}
82+
83+
return plaintext;
84+
}
85+
86+
private static byte[] EncryptStringToBytes(string plainText, byte[] key, byte[] iv)
87+
{
88+
// Check arguments.
89+
if (plainText == null || plainText.Length <= 0)
90+
{
91+
throw new ArgumentNullException("plainText");
92+
}
93+
if (key == null || key.Length <= 0)
94+
{
95+
throw new ArgumentNullException("key");
96+
}
97+
if (iv == null || iv.Length <= 0)
98+
{
99+
throw new ArgumentNullException("key");
100+
}
101+
byte[] encrypted;
102+
// Create a RijndaelManaged object
103+
// with the specified key and IV.
104+
using (var rijAlg = new RijndaelManaged())
105+
{
106+
rijAlg.Mode = CipherMode.CBC;
107+
rijAlg.Padding = PaddingMode.PKCS7;
108+
rijAlg.FeedbackSize = 128;
109+
110+
rijAlg.Key = key;
111+
rijAlg.IV = iv;
112+
113+
// Create a decrytor to perform the stream transform.
114+
var encryptor = rijAlg.CreateEncryptor(rijAlg.Key, rijAlg.IV);
115+
116+
// Create the streams used for encryption.
117+
using (var msEncrypt = new MemoryStream())
118+
{
119+
using (var csEncrypt = new CryptoStream(msEncrypt, encryptor, CryptoStreamMode.Write))
120+
{
121+
using (var swEncrypt = new StreamWriter(csEncrypt))
122+
{
123+
//Write all data to the stream.
124+
swEncrypt.Write(plainText);
125+
}
126+
encrypted = msEncrypt.ToArray();
127+
}
128+
}
129+
}
130+
131+
// Return the encrypted bytes from the memory stream.
132+
return encrypted;
133+
}
134+
}
135+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Text;
5+
using Microsoft.Web.WebPages.OAuth;
6+
using Encrypt_JavaScript_Decrypt_Csharp.Models;
7+
8+
namespace Encrypt_JavaScript_Decrypt_Csharp
9+
{
10+
public static class AuthConfig
11+
{
12+
public static void RegisterAuth()
13+
{
14+
// To let users of this site log in using their accounts from other sites such as Microsoft, Facebook, and Twitter,
15+
// you must update this site. For more information visit http://go.microsoft.com/fwlink/?LinkID=252166
16+
17+
//OAuthWebSecurity.RegisterMicrosoftClient(
18+
// clientId: "",
19+
// clientSecret: "");
20+
21+
//OAuthWebSecurity.RegisterTwitterClient(
22+
// consumerKey: "",
23+
// consumerSecret: "");
24+
25+
//OAuthWebSecurity.RegisterFacebookClient(
26+
// appId: "",
27+
// appSecret: "");
28+
29+
//OAuthWebSecurity.RegisterGoogleClient();
30+
}
31+
}
32+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
using System.Web;
2+
using System.Web.Optimization;
3+
4+
namespace Encrypt_JavaScript_Decrypt_Csharp
5+
{
6+
public class BundleConfig
7+
{
8+
// For more information on Bundling, visit http://go.microsoft.com/fwlink/?LinkId=254725
9+
public static void RegisterBundles(BundleCollection bundles)
10+
{
11+
bundles.Add(new ScriptBundle("~/bundles/jquery").Include(
12+
"~/Scripts/jquery-{version}.js"));
13+
14+
bundles.Add(new ScriptBundle("~/bundles/jqueryui").Include(
15+
"~/Scripts/jquery-ui-{version}.js"));
16+
17+
bundles.Add(new ScriptBundle("~/bundles/jqueryval").Include(
18+
"~/Scripts/jquery.unobtrusive*",
19+
"~/Scripts/jquery.validate*"));
20+
21+
// Use the development version of Modernizr to develop with and learn from. Then, when you're
22+
// ready for production, use the build tool at http://modernizr.com to pick only the tests you need.
23+
bundles.Add(new ScriptBundle("~/bundles/modernizr").Include(
24+
"~/Scripts/modernizr-*"));
25+
26+
bundles.Add(new StyleBundle("~/Content/css").Include("~/Content/site.css"));
27+
28+
bundles.Add(new StyleBundle("~/Content/themes/base/css").Include(
29+
"~/Content/themes/base/jquery.ui.core.css",
30+
"~/Content/themes/base/jquery.ui.resizable.css",
31+
"~/Content/themes/base/jquery.ui.selectable.css",
32+
"~/Content/themes/base/jquery.ui.accordion.css",
33+
"~/Content/themes/base/jquery.ui.autocomplete.css",
34+
"~/Content/themes/base/jquery.ui.button.css",
35+
"~/Content/themes/base/jquery.ui.dialog.css",
36+
"~/Content/themes/base/jquery.ui.slider.css",
37+
"~/Content/themes/base/jquery.ui.tabs.css",
38+
"~/Content/themes/base/jquery.ui.datepicker.css",
39+
"~/Content/themes/base/jquery.ui.progressbar.css",
40+
"~/Content/themes/base/jquery.ui.theme.css"));
41+
}
42+
}
43+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
using System.Web;
2+
using System.Web.Mvc;
3+
4+
namespace Encrypt_JavaScript_Decrypt_Csharp
5+
{
6+
public class FilterConfig
7+
{
8+
public static void RegisterGlobalFilters(GlobalFilterCollection filters)
9+
{
10+
filters.Add(new HandleErrorAttribute());
11+
}
12+
}
13+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Web;
5+
using System.Web.Mvc;
6+
using System.Web.Routing;
7+
8+
namespace Encrypt_JavaScript_Decrypt_Csharp
9+
{
10+
public class RouteConfig
11+
{
12+
public static void RegisterRoutes(RouteCollection routes)
13+
{
14+
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
15+
16+
routes.MapRoute(
17+
name: "Default",
18+
url: "{controller}/{action}/{id}",
19+
defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }
20+
);
21+
}
22+
}
23+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Web.Http;
5+
6+
namespace Encrypt_JavaScript_Decrypt_Csharp
7+
{
8+
public static class WebApiConfig
9+
{
10+
public static void Register(HttpConfiguration config)
11+
{
12+
config.Routes.MapHttpRoute(
13+
name: "DefaultApi",
14+
routeTemplate: "api/{controller}/{id}",
15+
defaults: new { id = RouteParameter.Optional }
16+
);
17+
}
18+
}
19+
}

0 commit comments

Comments
 (0)