-
Notifications
You must be signed in to change notification settings - Fork 90
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'feature/save-password' into devel
- Loading branch information
Showing
20 changed files
with
714 additions
and
62 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
// Copyright 2004-2017 The Poderosa Project. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
using Poderosa; | ||
using System; | ||
using System.IO; | ||
using System.Security.Cryptography; | ||
using System.Text; | ||
|
||
namespace Poderosa.Protocols { | ||
|
||
|
||
/// <summary> | ||
/// Simple string encyption with constant key. | ||
/// </summary> | ||
internal class SimpleStringEncrypt { | ||
|
||
// Method : DES | ||
// Mode : CBC | ||
// IV : 91 7c 0b f1 7e 3e 7e 33 | ||
// Key : 15 b1 84 59 15 60 29 32 | ||
|
||
private const string CIV = "kXwL8X4+fjM="; | ||
private const string CKEY = "FbGEWRVgKTI="; | ||
|
||
private SymmetricAlgorithm mCSP = new DESCryptoServiceProvider(); | ||
|
||
/// <summary> | ||
/// Decrypt string. | ||
/// </summary> | ||
/// <param name="s">Base64-encoded encrypted data</param> | ||
/// <returns>decrypted text or null if failed</returns> | ||
public string DecryptString(string s) { | ||
if (s == null) | ||
return null; | ||
if (s.Length == 0) | ||
return null; | ||
|
||
using (ICryptoTransform transform = this.mCSP.CreateDecryptor(Convert.FromBase64String(CKEY), Convert.FromBase64String(CIV))) { | ||
try { | ||
byte[] buffer = Convert.FromBase64String(s); | ||
using (MemoryStream stream = new MemoryStream()) { | ||
using (CryptoStream stream2 = new CryptoStream(stream, transform, CryptoStreamMode.Write)) { | ||
stream2.Write(buffer, 0, buffer.Length); | ||
stream2.FlushFinalBlock(); | ||
stream2.Close(); | ||
return Encoding.UTF8.GetString(stream.ToArray()); | ||
} | ||
} | ||
} | ||
catch (Exception exception) { | ||
RuntimeUtil.SilentReportException(exception); | ||
return null; | ||
} | ||
} | ||
} | ||
|
||
/// <summary> | ||
/// Encrypt string. | ||
/// </summary> | ||
/// <param name="text">Text to encrypt</param> | ||
/// <returns>Base64-encoded encrypted data or null if failed</returns> | ||
public string EncryptString(string text) { | ||
if (text == null) | ||
return null; | ||
|
||
try { | ||
using (ICryptoTransform transform = this.mCSP.CreateEncryptor(Convert.FromBase64String(CKEY), Convert.FromBase64String(CIV))) { | ||
byte[] bytes = Encoding.UTF8.GetBytes(text); | ||
using (MemoryStream stream = new MemoryStream()) { | ||
using (CryptoStream stream2 = new CryptoStream(stream, transform, CryptoStreamMode.Write)) { | ||
stream2.Write(bytes, 0, bytes.Length); | ||
stream2.FlushFinalBlock(); | ||
stream2.Close(); | ||
return Convert.ToBase64String(stream.ToArray()); | ||
} | ||
} | ||
} | ||
} | ||
catch (Exception exception) { | ||
RuntimeUtil.SilentReportException(exception); | ||
return null; | ||
} | ||
} | ||
} | ||
} |
Oops, something went wrong.