/*
Kooboo is a content management system based on ASP.NET MVC framework. Copyright 2009 Yardi Technology Limited.
This program is free software: you can redistribute it and/or modify it under the terms of the
GNU General Public License version 3 as published by the Free Software Foundation.
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License along with this program.
If not, see http://www.kooboo.com/gpl3/.
*/
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Everest.Library.Providers.Cryptography{
/// <summary>
/// Cryptographer
/// </summary>
public static class Cryptographer
{
/// <summary>
///
/// </summary>
static volatile ICryptographyProvider cryptographyProvider = null;
static object lockHelper = new object();
/// <summary>
/// Gets the cryptography provider.
/// </summary>
/// <value>The cryptography provider.</value>
public static ICryptographyProvider CryptographyProvider
{
get
{
if (cryptographyProvider == null)
{
lock (lockHelper)
{
if (cryptographyProvider == null)
{
cryptographyProvider = UnityManager.Resolve<ICryptographyProvider>();
}
}
}
return cryptographyProvider;
}
}
/// <summary>
/// Compares plain text input with a computed hash .
/// </summary>
/// <param name="plaintext">The plaintext.</param>
/// <param name="hashedText">The hashed text.</param>
/// <returns></returns>
public static bool CompareHash(string plaintext, string hashedText)
{
return cryptographyProvider.CompareHash(plaintext, hashedText);
}
/// <summary>
/// Compares plain text input with a computed hash.
/// </summary>
/// <param name="plaintext">The plaintext.</param>
/// <param name="hashedText">The hashed text.</param>
/// <returns></returns>
public static bool CompareHash(byte[] plaintext, byte[] hashedText)
{
return cryptographyProvider.CompareHash(plaintext, hashedText);
}
/// <summary>
/// Computes the hash value of plain text.
/// </summary>
/// <param name="plainText">The plain text.</param>
/// <returns></returns>
public static string CreateHash(string plainText)
{
return cryptographyProvider.CreateHash(plainText);
}
/// <summary>
/// Computes the hash value of plain text.
/// </summary>
/// <param name="plaintext">The plaintext.</param>
/// <returns></returns>
public static byte[] CreateHash(byte[] plaintext)
{
return cryptographyProvider.CreateHash(plaintext);
}
/// <summary>
/// Decrypts a cipher text.
/// </summary>
/// <param name="ciphertext">The ciphertext.</param>
/// <returns></returns>
public static byte[] DecryptSymmetric(byte[] ciphertext)
{
return cryptographyProvider.DecryptSymmetric(ciphertext);
}
/// <summary>
/// Decrypts a cipher text.
/// </summary>
/// <param name="ciphertextBase64">The ciphertext base64.</param>
/// <returns></returns>
public static string DecryptSymmetric(string ciphertextBase64)
{
return cryptographyProvider.DecryptSymmetric(ciphertextBase64);
}
/// <summary>
/// Encrypts a secret.
/// </summary>
/// <param name="plaintext">The plaintext.</param>
/// <returns></returns>
public static byte[] EncryptSymmetric(byte[] plaintext)
{
return cryptographyProvider.EncryptSymmetric(plaintext);
}
/// <summary>
/// Encrypts a secret.
/// </summary>
/// <param name="plaintext">The plaintext.</param>
/// <returns></returns>
public static string EncryptSymmetric(string plaintext)
{
return cryptographyProvider.EncryptSymmetric(plaintext);
}
}
}
|