Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit300e92b

Browse files
update
1 parent022216c commit300e92b

File tree

2 files changed

+67
-1
lines changed

2 files changed

+67
-1
lines changed

‎ebOS/Crypt.cs‎

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
usingSystem;
2+
usingSystem.IO;
3+
usingSystem.Security.Cryptography;
4+
usingSystem.Text;
5+
6+
namespaceebOS
7+
{
8+
publicstaticclassEncrypt
9+
{
10+
// This size of the IV (in bytes) must = (keysize / 8). Default keysize is 256, so the IV must be
11+
// 32 bytes long. Using a 16 character string here gives us 32 bytes when converted to a byte array.
12+
privateconststringinitVector="hfwlpghybmfaaptl";
13+
// This constant is used to determine the keysize of the encryption algorithm
14+
privateconstintkeysize=256;
15+
//Encrypt
16+
publicstaticstringEncryptString(stringplainText,stringpassPhrase)
17+
{
18+
byte[]initVectorBytes=Encoding.UTF8.GetBytes(initVector);
19+
byte[]plainTextBytes=Encoding.UTF8.GetBytes(plainText);
20+
PasswordDeriveBytespassword=newPasswordDeriveBytes(passPhrase,null);
21+
byte[]keyBytes=password.GetBytes(keysize/8);
22+
RijndaelManagedsymmetricKey=newRijndaelManaged();
23+
symmetricKey.Mode=CipherMode.CBC;
24+
ICryptoTransformencryptor=symmetricKey.CreateEncryptor(keyBytes,initVectorBytes);
25+
MemoryStreammemoryStream=newMemoryStream();
26+
CryptoStreamcryptoStream=newCryptoStream(memoryStream,encryptor,CryptoStreamMode.Write);
27+
cryptoStream.Write(plainTextBytes,0,plainTextBytes.Length);
28+
cryptoStream.FlushFinalBlock();
29+
byte[]cipherTextBytes=memoryStream.ToArray();
30+
memoryStream.Close();
31+
cryptoStream.Close();
32+
returnConvert.ToBase64String(cipherTextBytes);
33+
}
34+
//Decrypt
35+
publicstaticstringDecryptString(stringcipherText,stringpassPhrase)
36+
{
37+
byte[]initVectorBytes=Encoding.UTF8.GetBytes(initVector);
38+
byte[]cipherTextBytes=Convert.FromBase64String(cipherText);
39+
PasswordDeriveBytespassword=newPasswordDeriveBytes(passPhrase,null);
40+
byte[]keyBytes=password.GetBytes(keysize/8);
41+
RijndaelManagedsymmetricKey=newRijndaelManaged();
42+
symmetricKey.Mode=CipherMode.CBC;
43+
ICryptoTransformdecryptor=symmetricKey.CreateDecryptor(keyBytes,initVectorBytes);
44+
MemoryStreammemoryStream=newMemoryStream(cipherTextBytes);
45+
CryptoStreamcryptoStream=newCryptoStream(memoryStream,decryptor,CryptoStreamMode.Read);
46+
byte[]plainTextBytes=newbyte[cipherTextBytes.Length];
47+
intdecryptedByteCount=cryptoStream.Read(plainTextBytes,0,plainTextBytes.Length);
48+
memoryStream.Close();
49+
cryptoStream.Close();
50+
returnEncoding.UTF8.GetString(plainTextBytes,0,decryptedByteCount);
51+
}
52+
}
53+
}

‎ebOS/Kernel.cs‎

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ public class Kernel : Sys.Kernel
1111
{
1212
privateconststringver="1.0.0";
1313
privateconststringcalcver="1.0.0";
14+
privateconststringcryptver="1.0.0";
1415
protectedoverridevoidBeforeRun()
1516
{
1617
Console.WriteLine("ebOS booted successfully.");
@@ -43,6 +44,7 @@ void help()
4344
4445
terminal:
4546
cls - clear terminal
47+
echo - echo text
4648
4749
apps:
4850
calc - calculator
@@ -122,10 +124,21 @@ void help()
122124
break;
123125
//apps
124126
case"calc":
125-
Console.WriteLine("calc "+ver);
127+
Console.WriteLine("calc "+calcver);
126128
Console.WriteLine("Evaluate expression:");
127129
EvaluateString.Run();
128130
break;
131+
case"crypt":
132+
Console.WriteLine("crypt "+cryptver);
133+
Console.Write("Encrypt or decrypt? ");
134+
stringinput=Console.ReadLine();
135+
if(input=="encrypt")
136+
{
137+
Console.Write("text: ");
138+
stringtextinput=Console.ReadLine();
139+
Console.WriteLine(Encrypt.EncryptString(textinput));
140+
}
141+
break;
129142
//no reason
130143
case"hello":
131144
Console.WriteLine("Hello World");

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp