You've already forked linux-packaging-mono
Imported Upstream version 4.2.0.179
Former-commit-id: 4610231f55806d2a05ed69e5ff3faa7336cc1479
This commit is contained in:
committed by
Jo Shields
parent
aa7da660d6
commit
c042cd0c52
@ -1,82 +0,0 @@
|
||||
//
|
||||
// System.Security.Cryptography.Aes.cs
|
||||
// based on mcs/class/corlib/System.Security.Cryptography/Rijndael.cs
|
||||
//
|
||||
// Authors:
|
||||
// Dan Lewis (dihlewis@yahoo.co.uk)
|
||||
// Andrew Birkett (andy@nobugs.org)
|
||||
// Sebastien Pouliot <sebastien@ximian.com>
|
||||
//
|
||||
// (C) 2002
|
||||
// Copyright (C) 2004-2006,2008 Novell, Inc (http://www.novell.com)
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining
|
||||
// a copy of this software and associated documentation files (the
|
||||
// "Software"), to deal in the Software without restriction, including
|
||||
// without limitation the rights to use, copy, modify, merge, publish,
|
||||
// distribute, sublicense, and/or sell copies of the Software, and to
|
||||
// permit persons to whom the Software is furnished to do so, subject to
|
||||
// the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be
|
||||
// included in all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
namespace System.Security.Cryptography {
|
||||
|
||||
// References:
|
||||
// a. FIPS PUB 197: Advanced Encryption Standard
|
||||
// http://csrc.nist.gov/publications/fips/fips197/fips-197.pdf
|
||||
|
||||
// since 4.0 (both FX and SL) this type now resides inside mscorlib.dll and link back to System.Core.dll
|
||||
#if MOBILE
|
||||
// version has not changed between SL3 (System.Core) and SL4
|
||||
[TypeForwardedFrom (Consts.AssemblySystem_Core)]
|
||||
#else
|
||||
// use 3.5 version
|
||||
[TypeForwardedFrom ("System.Core, Version=3.5.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089")]
|
||||
#endif
|
||||
public abstract class Aes : SymmetricAlgorithm {
|
||||
|
||||
public static new Aes Create ()
|
||||
{
|
||||
#if FULL_AOT_RUNTIME
|
||||
// The Aes base class was moved from System.Core to mscorlib - so we can't just return a new AesCryptoServiceProvider instance
|
||||
// note: the linker is aware of this condition
|
||||
return (Aes) Activator.CreateInstance (Type.GetType ("System.Security.Cryptography.AesManaged, " + Consts.AssemblySystem_Core));
|
||||
#else
|
||||
return Create ("System.Security.Cryptography.AesCryptoServiceProvider, " + Consts.AssemblySystem_Core);
|
||||
#endif
|
||||
}
|
||||
|
||||
public static new Aes Create (string algorithmName)
|
||||
{
|
||||
return (Aes) CryptoConfig.CreateFromName (algorithmName);
|
||||
}
|
||||
|
||||
protected Aes ()
|
||||
{
|
||||
KeySizeValue = 256;
|
||||
BlockSizeValue = 128;
|
||||
FeedbackSizeValue = 128;
|
||||
|
||||
LegalKeySizesValue = new KeySizes [1];
|
||||
LegalKeySizesValue [0] = new KeySizes (128, 256, 64);
|
||||
|
||||
LegalBlockSizesValue = new KeySizes [1];
|
||||
LegalBlockSizesValue [0] = new KeySizes (128, 128, 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,119 +0,0 @@
|
||||
//
|
||||
// System.Security.Cryptography.AsymmetricAlgorithm Class implementation
|
||||
//
|
||||
// Authors:
|
||||
// Thomas Neidhart (tome@sbox.tugraz.at)
|
||||
// Sebastien Pouliot (sebastien@ximian.com)
|
||||
//
|
||||
// Portions (C) 2002, 2003 Motus Technologies Inc. (http://www.motus.com)
|
||||
// Copyright (C) 2004-2005, 2008 Novell, Inc (http://www.novell.com)
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining
|
||||
// a copy of this software and associated documentation files (the
|
||||
// "Software"), to deal in the Software without restriction, including
|
||||
// without limitation the rights to use, copy, modify, merge, publish,
|
||||
// distribute, sublicense, and/or sell copies of the Software, and to
|
||||
// permit persons to whom the Software is furnished to do so, subject to
|
||||
// the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be
|
||||
// included in all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
using System.Globalization;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
namespace System.Security.Cryptography {
|
||||
|
||||
[ComVisible (true)]
|
||||
public abstract class AsymmetricAlgorithm : IDisposable {
|
||||
|
||||
protected int KeySizeValue;
|
||||
protected KeySizes[] LegalKeySizesValue;
|
||||
|
||||
protected AsymmetricAlgorithm ()
|
||||
{
|
||||
}
|
||||
|
||||
public abstract string KeyExchangeAlgorithm {
|
||||
get;
|
||||
}
|
||||
|
||||
public virtual int KeySize {
|
||||
get { return this.KeySizeValue; }
|
||||
set {
|
||||
if (!KeySizes.IsLegalKeySize (this.LegalKeySizesValue, value))
|
||||
throw new CryptographicException (Locale.GetText ("Key size not supported by algorithm."));
|
||||
|
||||
this.KeySizeValue = value;
|
||||
}
|
||||
}
|
||||
|
||||
public virtual KeySizes[] LegalKeySizes {
|
||||
get { return this.LegalKeySizesValue; }
|
||||
}
|
||||
|
||||
public abstract string SignatureAlgorithm {
|
||||
get;
|
||||
}
|
||||
|
||||
public void Dispose ()
|
||||
{
|
||||
Dispose (true);
|
||||
GC.SuppressFinalize (this); // Finalization is now unnecessary
|
||||
}
|
||||
|
||||
public void Clear ()
|
||||
{
|
||||
Dispose (false);
|
||||
}
|
||||
|
||||
protected virtual void Dispose (bool disposing)
|
||||
{
|
||||
}
|
||||
public abstract void FromXmlString (string xmlString);
|
||||
|
||||
public abstract string ToXmlString (bool includePrivateParameters);
|
||||
|
||||
public static AsymmetricAlgorithm Create ()
|
||||
{
|
||||
#if FULL_AOT_RUNTIME
|
||||
return new RSACryptoServiceProvider ();
|
||||
#else
|
||||
return Create ("System.Security.Cryptography.AsymmetricAlgorithm");
|
||||
#endif
|
||||
}
|
||||
|
||||
public static AsymmetricAlgorithm Create (string algName)
|
||||
{
|
||||
return (AsymmetricAlgorithm) CryptoConfig.CreateFromName (algName);
|
||||
}
|
||||
|
||||
// parsing helper shared between DSA and RSA
|
||||
internal static byte [] GetNamedParam (string xml, string param)
|
||||
{
|
||||
string start_element = "<" + param + ">";
|
||||
int start = xml.IndexOf (start_element);
|
||||
if (start == -1)
|
||||
return null;
|
||||
|
||||
string end_element = "</" + param + ">";
|
||||
int end = xml.IndexOf (end_element);
|
||||
if ((end == -1) || (end <= start))
|
||||
return null;
|
||||
|
||||
start += start_element.Length;
|
||||
|
||||
string base64 = xml.Substring (start, end - start);
|
||||
return Convert.FromBase64String (base64);
|
||||
}
|
||||
}
|
||||
}
|
@ -1,48 +0,0 @@
|
||||
//
|
||||
// System.Security.Cryptography AsymmetricKeyExchangeDeformatter Class implementation
|
||||
//
|
||||
// Authors:
|
||||
// Thomas Neidhart (tome@sbox.tugraz.at)
|
||||
//
|
||||
// Copyright (C) 2004-2006 Novell, Inc (http://www.novell.com)
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining
|
||||
// a copy of this software and associated documentation files (the
|
||||
// "Software"), to deal in the Software without restriction, including
|
||||
// without limitation the rights to use, copy, modify, merge, publish,
|
||||
// distribute, sublicense, and/or sell copies of the Software, and to
|
||||
// permit persons to whom the Software is furnished to do so, subject to
|
||||
// the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be
|
||||
// included in all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
namespace System.Security.Cryptography {
|
||||
|
||||
[ComVisible (true)]
|
||||
public abstract class AsymmetricKeyExchangeDeformatter {
|
||||
protected AsymmetricKeyExchangeDeformatter ()
|
||||
{
|
||||
}
|
||||
|
||||
public abstract string Parameters {
|
||||
get;
|
||||
set;
|
||||
}
|
||||
|
||||
public abstract byte[] DecryptKeyExchange (byte[] rgb);
|
||||
|
||||
public abstract void SetKey (AsymmetricAlgorithm key);
|
||||
}
|
||||
}
|
@ -1,51 +0,0 @@
|
||||
//
|
||||
// System.Security.Cryptography AsymmetricKeyExchangeFormatter Class implementation
|
||||
//
|
||||
// Authors:
|
||||
// Thomas Neidhart (tome@sbox.tugraz.at)
|
||||
//
|
||||
// Copyright (C) 2004-2006 Novell, Inc (http://www.novell.com)
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining
|
||||
// a copy of this software and associated documentation files (the
|
||||
// "Software"), to deal in the Software without restriction, including
|
||||
// without limitation the rights to use, copy, modify, merge, publish,
|
||||
// distribute, sublicense, and/or sell copies of the Software, and to
|
||||
// permit persons to whom the Software is furnished to do so, subject to
|
||||
// the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be
|
||||
// included in all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
namespace System.Security.Cryptography {
|
||||
|
||||
[ComVisible (true)]
|
||||
public abstract class AsymmetricKeyExchangeFormatter {
|
||||
|
||||
protected AsymmetricKeyExchangeFormatter ()
|
||||
{
|
||||
}
|
||||
|
||||
public abstract string Parameters {
|
||||
get;
|
||||
}
|
||||
|
||||
public abstract byte[] CreateKeyExchange (byte[] data);
|
||||
|
||||
public abstract byte[] CreateKeyExchange (byte[] data, Type symAlgType);
|
||||
|
||||
public abstract void SetKey (AsymmetricAlgorithm key);
|
||||
}
|
||||
}
|
||||
|
@ -1,57 +0,0 @@
|
||||
//
|
||||
// System.Security.Cryptography AsymmetricSignatureDeformatter Class implementation
|
||||
//
|
||||
// Authors:
|
||||
// Thomas Neidhart (tome@sbox.tugraz.at)
|
||||
//
|
||||
// Copyright (C) 2004-2006 Novell, Inc (http://www.novell.com)
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining
|
||||
// a copy of this software and associated documentation files (the
|
||||
// "Software"), to deal in the Software without restriction, including
|
||||
// without limitation the rights to use, copy, modify, merge, publish,
|
||||
// distribute, sublicense, and/or sell copies of the Software, and to
|
||||
// permit persons to whom the Software is furnished to do so, subject to
|
||||
// the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be
|
||||
// included in all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
namespace System.Security.Cryptography {
|
||||
|
||||
[ComVisible (true)]
|
||||
public abstract class AsymmetricSignatureDeformatter {
|
||||
|
||||
protected AsymmetricSignatureDeformatter ()
|
||||
{
|
||||
}
|
||||
|
||||
public abstract void SetHashAlgorithm (string strName);
|
||||
|
||||
public abstract void SetKey (AsymmetricAlgorithm key);
|
||||
|
||||
public abstract bool VerifySignature (byte[] rgbHash, byte[] rgbSignature);
|
||||
|
||||
public virtual bool VerifySignature (HashAlgorithm hash, byte[] rgbSignature)
|
||||
{
|
||||
if (hash == null)
|
||||
throw new ArgumentNullException ("hash");
|
||||
|
||||
SetHashAlgorithm (hash.ToString ());
|
||||
|
||||
return VerifySignature (hash.Hash, rgbSignature);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,55 +0,0 @@
|
||||
//
|
||||
// System.Security.Cryptography AsymmetricSignatureFormatter Class implementation
|
||||
//
|
||||
// Authors:
|
||||
// Thomas Neidhart (tome@sbox.tugraz.at)
|
||||
//
|
||||
// Copyright (C) 2004-2006 Novell, Inc (http://www.novell.com)
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining
|
||||
// a copy of this software and associated documentation files (the
|
||||
// "Software"), to deal in the Software without restriction, including
|
||||
// without limitation the rights to use, copy, modify, merge, publish,
|
||||
// distribute, sublicense, and/or sell copies of the Software, and to
|
||||
// permit persons to whom the Software is furnished to do so, subject to
|
||||
// the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be
|
||||
// included in all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
namespace System.Security.Cryptography {
|
||||
|
||||
[ComVisible (true)]
|
||||
public abstract class AsymmetricSignatureFormatter {
|
||||
|
||||
protected AsymmetricSignatureFormatter ()
|
||||
{ }
|
||||
|
||||
public abstract void SetHashAlgorithm (string strName);
|
||||
|
||||
public abstract void SetKey (AsymmetricAlgorithm key);
|
||||
|
||||
public abstract byte[] CreateSignature (byte[] rgbHash);
|
||||
|
||||
public virtual byte[] CreateSignature (HashAlgorithm hash)
|
||||
{
|
||||
if (hash == null)
|
||||
throw new ArgumentNullException ("hash");
|
||||
|
||||
SetHashAlgorithm (hash.ToString ());
|
||||
return CreateSignature (hash.Hash);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,84 +0,0 @@
|
||||
//
|
||||
// System.Security.Cryptography.Base64Constants
|
||||
//
|
||||
// Authors:
|
||||
// Sergey Chaban (serge@wildwestsoftware.com)
|
||||
// Sebastien Pouliot <sebastien@ximian.com>
|
||||
//
|
||||
// Copyright (C) 2004-2005 Novell, Inc (http://www.novell.com)
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining
|
||||
// a copy of this software and associated documentation files (the
|
||||
// "Software"), to deal in the Software without restriction, including
|
||||
// without limitation the rights to use, copy, modify, merge, publish,
|
||||
// distribute, sublicense, and/or sell copies of the Software, and to
|
||||
// permit persons to whom the Software is furnished to do so, subject to
|
||||
// the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be
|
||||
// included in all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
namespace System.Security.Cryptography {
|
||||
|
||||
internal static class Base64Constants {
|
||||
// Pre-calculated tables
|
||||
|
||||
public static readonly byte[] EncodeTable = {
|
||||
0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47, 0x48, 0x49, 0x4A, 0x4B, 0x4C, 0x4D, 0x4E, 0x4F, 0x50,
|
||||
0x51, 0x52, 0x53, 0x54, 0x55, 0x56, 0x57, 0x58, 0x59, 0x5A, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66,
|
||||
0x67, 0x68, 0x69, 0x6A, 0x6B, 0x6C, 0x6D, 0x6E, 0x6F, 0x70, 0x71, 0x72, 0x73, 0x74, 0x75, 0x76,
|
||||
0x77, 0x78, 0x79, 0x7A, 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38, 0x39, 0x2B, 0x2F
|
||||
};
|
||||
|
||||
public static readonly byte[] DecodeTable = {
|
||||
0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
|
||||
0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
|
||||
0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x3E, 0xFF, 0xFF, 0xFF, 0x3F,
|
||||
0x34, 0x35, 0x36, 0x37, 0x38, 0x39, 0x3A, 0x3B, 0x3C, 0x3D, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
|
||||
0xFF, 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E,
|
||||
0x0F, 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, 0x19, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
|
||||
0xFF, 0x1A, 0x1B, 0x1C, 0x1D, 0x1E, 0x1F, 0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27, 0x28,
|
||||
0x29, 0x2A, 0x2B, 0x2C, 0x2D, 0x2E, 0x2F, 0x30, 0x31, 0x32, 0x33
|
||||
};
|
||||
|
||||
// This code was used to generated the tables
|
||||
/*
|
||||
// This is the Base64 alphabet as described in RFC 2045 (Table 1, page 25).
|
||||
private static string ALPHABET = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
|
||||
|
||||
private static byte[] encodeTable;
|
||||
private static byte[] decodeTable;
|
||||
|
||||
static Base64Constants ()
|
||||
{
|
||||
int len = ALPHABET.Length;
|
||||
|
||||
encodeTable = new byte [len];
|
||||
|
||||
for (int i=0; i < len; i++) {
|
||||
encodeTable [i] = (byte) ALPHABET [i];
|
||||
}
|
||||
|
||||
decodeTable = new byte [1 + (int)'z'];
|
||||
|
||||
for (int i=0; i < decodeTable.Length; i++) {
|
||||
decodeTable [i] = Byte.MaxValue;
|
||||
}
|
||||
|
||||
for (int i=0; i < len; i++) {
|
||||
char ch = ALPHABET [i];
|
||||
decodeTable [(int)ch] = (byte) i;
|
||||
}
|
||||
}
|
||||
*/
|
||||
}
|
||||
}
|
@ -1,44 +0,0 @@
|
||||
//
|
||||
// System.Security.Cryptography CipherMode enumeration
|
||||
//
|
||||
// Authors:
|
||||
// Matthew S. Ford (Matthew.S.Ford@Rose-Hulman.Edu)
|
||||
//
|
||||
// Copyright 2001 by Matthew S. Ford.
|
||||
// Copyright (C) 2004-2005 Novell, Inc (http://www.novell.com)
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining
|
||||
// a copy of this software and associated documentation files (the
|
||||
// "Software"), to deal in the Software without restriction, including
|
||||
// without limitation the rights to use, copy, modify, merge, publish,
|
||||
// distribute, sublicense, and/or sell copies of the Software, and to
|
||||
// permit persons to whom the Software is furnished to do so, subject to
|
||||
// the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be
|
||||
// included in all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
namespace System.Security.Cryptography {
|
||||
|
||||
[Serializable]
|
||||
[ComVisible (true)]
|
||||
public enum CipherMode {
|
||||
CBC = 0x1, // Cipher Block Chaining
|
||||
ECB, // Electronic Codebook
|
||||
OFB, // Output Feedback
|
||||
CFB, // Cipher Feedback
|
||||
CTS, // Cipher Text Stealing
|
||||
}
|
||||
}
|
||||
|
@ -41,6 +41,7 @@ using System.Runtime.CompilerServices;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Security.Permissions;
|
||||
using System.Text;
|
||||
using System.Security.Cryptography.X509Certificates;
|
||||
|
||||
using Mono.Xml;
|
||||
|
||||
@ -511,6 +512,11 @@ public partial class CryptoConfig {
|
||||
}
|
||||
}
|
||||
|
||||
internal static string MapNameToOID (string name, OidGroup oidGroup)
|
||||
{
|
||||
return MapNameToOID (name);
|
||||
}
|
||||
|
||||
public static string MapNameToOID (string name)
|
||||
{
|
||||
if (name == null)
|
||||
@ -527,11 +533,6 @@ public partial class CryptoConfig {
|
||||
return result;
|
||||
}
|
||||
|
||||
[MonoLimitation ("nothing is FIPS certified so it never make sense to restrict to this (empty) subset")]
|
||||
public static bool AllowOnlyFipsAlgorithms {
|
||||
get { return false; }
|
||||
}
|
||||
|
||||
public static void AddAlgorithm (Type algorithm, params string[] names)
|
||||
{
|
||||
if (algorithm == null)
|
||||
|
@ -185,6 +185,11 @@ namespace System.Security.Cryptography {
|
||||
}
|
||||
}
|
||||
|
||||
internal static string MapNameToOID (string name, object arg)
|
||||
{
|
||||
return MapNameToOID (name);
|
||||
}
|
||||
|
||||
public static string MapNameToOID (string name)
|
||||
{
|
||||
if (name == null)
|
||||
|
@ -124,6 +124,11 @@ namespace System.Security.Cryptography {
|
||||
}
|
||||
return num;
|
||||
}
|
||||
|
||||
[MonoLimitation ("nothing is FIPS certified so it never make sense to restrict to this (empty) subset")]
|
||||
public static bool AllowOnlyFipsAlgorithms {
|
||||
get { return false; }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1,377 +0,0 @@
|
||||
//
|
||||
// System.Security.Cryptography CryptoStream.cs
|
||||
//
|
||||
// Authors:
|
||||
// Thomas Neidhart (tome@sbox.tugraz.at)
|
||||
// Sebastien Pouliot (sebastien@ximian.com)
|
||||
//
|
||||
// Portions (C) 2002, 2003 Motus Technologies Inc. (http://www.motus.com)
|
||||
// Copyright (C) 2004-2005, 2007 Novell, Inc (http://www.novell.com)
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining
|
||||
// a copy of this software and associated documentation files (the
|
||||
// "Software"), to deal in the Software without restriction, including
|
||||
// without limitation the rights to use, copy, modify, merge, publish,
|
||||
// distribute, sublicense, and/or sell copies of the Software, and to
|
||||
// permit persons to whom the Software is furnished to do so, subject to
|
||||
// the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be
|
||||
// included in all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
using System.Globalization;
|
||||
using System.IO;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace System.Security.Cryptography {
|
||||
|
||||
[ComVisible (true)]
|
||||
public class CryptoStream : Stream {
|
||||
private Stream _stream;
|
||||
private ICryptoTransform _transform;
|
||||
private CryptoStreamMode _mode;
|
||||
private byte[] _currentBlock;
|
||||
private bool _disposed;
|
||||
private bool _flushedFinalBlock;
|
||||
private int _partialCount;
|
||||
private bool _endOfStream;
|
||||
|
||||
private byte[] _waitingBlock;
|
||||
private int _waitingCount;
|
||||
|
||||
private byte[] _transformedBlock;
|
||||
private int _transformedPos;
|
||||
private int _transformedCount;
|
||||
|
||||
private byte[] _workingBlock;
|
||||
private int _workingCount;
|
||||
|
||||
public CryptoStream (Stream stream, ICryptoTransform transform, CryptoStreamMode mode)
|
||||
{
|
||||
if (mode == CryptoStreamMode.Read) {
|
||||
if (!stream.CanRead)
|
||||
throw new ArgumentException (Locale.GetText ("Can't read on stream"));
|
||||
} else if (mode == CryptoStreamMode.Write) {
|
||||
if (!stream.CanWrite)
|
||||
throw new ArgumentException (Locale.GetText ("Can't write on stream"));
|
||||
} else {
|
||||
throw new ArgumentException ("mode");
|
||||
}
|
||||
_stream = stream;
|
||||
_transform = transform;
|
||||
_mode = mode;
|
||||
_disposed = false;
|
||||
if (transform != null) {
|
||||
_workingBlock = new byte [transform.InputBlockSize];
|
||||
}
|
||||
}
|
||||
|
||||
public override bool CanRead {
|
||||
get { return (_mode == CryptoStreamMode.Read); }
|
||||
}
|
||||
|
||||
public override bool CanSeek {
|
||||
get { return false; }
|
||||
}
|
||||
|
||||
public override bool CanWrite {
|
||||
get { return (_mode == CryptoStreamMode.Write); }
|
||||
}
|
||||
|
||||
public override long Length {
|
||||
get { throw new NotSupportedException ("Length"); }
|
||||
}
|
||||
|
||||
public override long Position {
|
||||
get { throw new NotSupportedException ("Position"); }
|
||||
set { throw new NotSupportedException ("Position"); }
|
||||
}
|
||||
|
||||
public void Clear ()
|
||||
{
|
||||
Close ();
|
||||
}
|
||||
|
||||
public override int Read ([In,Out] byte[] buffer, int offset, int count)
|
||||
{
|
||||
if (_mode != CryptoStreamMode.Read) {
|
||||
throw new NotSupportedException (
|
||||
Locale.GetText ("not in Read mode"));
|
||||
}
|
||||
if (offset < 0) {
|
||||
throw new ArgumentOutOfRangeException ("offset",
|
||||
Locale.GetText ("negative"));
|
||||
}
|
||||
if (count < 0) {
|
||||
throw new ArgumentOutOfRangeException ("count",
|
||||
Locale.GetText ("negative"));
|
||||
}
|
||||
// yes - buffer.Length will throw a NullReferenceException if buffer is null
|
||||
// but by doing so we match MS implementation
|
||||
// re-ordered to avoid integer overflow
|
||||
if (offset > buffer.Length - count) {
|
||||
throw new ArgumentException ("(offset+count)",
|
||||
Locale.GetText ("buffer overflow"));
|
||||
}
|
||||
// for some strange reason ObjectDisposedException isn't throw
|
||||
if (_workingBlock == null) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
int result = 0;
|
||||
if ((count == 0) || ((_transformedPos == _transformedCount) && (_endOfStream)))
|
||||
return result;
|
||||
|
||||
if (_waitingBlock == null) {
|
||||
_transformedBlock = new byte [_transform.OutputBlockSize << 2];
|
||||
_transformedPos = 0;
|
||||
_transformedCount = 0;
|
||||
_waitingBlock = new byte [_transform.InputBlockSize];
|
||||
_waitingCount = _stream.Read (_waitingBlock, 0, _waitingBlock.Length);
|
||||
}
|
||||
|
||||
while (count > 0) {
|
||||
// transformed but not yet returned
|
||||
int length = (_transformedCount - _transformedPos);
|
||||
|
||||
// need more data - at least one full block must be available if we haven't reach the end of the stream
|
||||
if (length < _transform.InputBlockSize) {
|
||||
int transformed = 0;
|
||||
|
||||
// load a new block
|
||||
_workingCount = _stream.Read (_workingBlock, 0, _transform.InputBlockSize);
|
||||
_endOfStream = (_workingCount < _transform.InputBlockSize);
|
||||
|
||||
if (!_endOfStream) {
|
||||
// transform the waiting block
|
||||
transformed = _transform.TransformBlock (_waitingBlock, 0, _waitingBlock.Length, _transformedBlock, _transformedCount);
|
||||
|
||||
// transfer temporary to waiting
|
||||
Buffer.BlockCopy (_workingBlock, 0, _waitingBlock, 0, _workingCount);
|
||||
_waitingCount = _workingCount;
|
||||
}
|
||||
else {
|
||||
if (_workingCount > 0) {
|
||||
// transform the waiting block
|
||||
transformed = _transform.TransformBlock (_waitingBlock, 0, _waitingBlock.Length, _transformedBlock, _transformedCount);
|
||||
|
||||
// transfer temporary to waiting
|
||||
Buffer.BlockCopy (_workingBlock, 0, _waitingBlock, 0, _workingCount);
|
||||
_waitingCount = _workingCount;
|
||||
|
||||
length += transformed;
|
||||
_transformedCount += transformed;
|
||||
}
|
||||
if (!_flushedFinalBlock) {
|
||||
byte[] input = _transform.TransformFinalBlock (_waitingBlock, 0, _waitingCount);
|
||||
transformed = input.Length;
|
||||
Buffer.BlockCopy (input, 0, _transformedBlock, _transformedCount, input.Length);
|
||||
// zeroize this last block
|
||||
Array.Clear (input, 0, input.Length);
|
||||
_flushedFinalBlock = true;
|
||||
}
|
||||
}
|
||||
|
||||
length += transformed;
|
||||
_transformedCount += transformed;
|
||||
}
|
||||
// compaction
|
||||
if (_transformedPos > _transform.OutputBlockSize) {
|
||||
Buffer.BlockCopy (_transformedBlock, _transformedPos, _transformedBlock, 0, length);
|
||||
_transformedCount -= _transformedPos;
|
||||
_transformedPos = 0;
|
||||
}
|
||||
|
||||
length = ((count < length) ? count : length);
|
||||
if (length > 0) {
|
||||
Buffer.BlockCopy (_transformedBlock, _transformedPos, buffer, offset, length);
|
||||
_transformedPos += length;
|
||||
|
||||
result += length;
|
||||
offset += length;
|
||||
count -= length;
|
||||
}
|
||||
|
||||
// there may not be enough data in the stream for a
|
||||
// complete block
|
||||
if (((length != _transform.InputBlockSize) && (_waitingCount != _transform.InputBlockSize)) || (_endOfStream)) {
|
||||
count = 0; // no more data can be read
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
public override void Write (byte[] buffer, int offset, int count)
|
||||
{
|
||||
if (_mode != CryptoStreamMode.Write) {
|
||||
throw new NotSupportedException (
|
||||
Locale.GetText ("not in Write mode"));
|
||||
}
|
||||
if (offset < 0) {
|
||||
throw new ArgumentOutOfRangeException ("offset",
|
||||
Locale.GetText ("negative"));
|
||||
}
|
||||
if (count < 0) {
|
||||
throw new ArgumentOutOfRangeException ("count",
|
||||
Locale.GetText ("negative"));
|
||||
}
|
||||
// re-ordered to avoid integer overflow
|
||||
if (offset > buffer.Length - count) {
|
||||
throw new ArgumentException ("(offset+count)",
|
||||
Locale.GetText ("buffer overflow"));
|
||||
}
|
||||
|
||||
if (_stream == null)
|
||||
throw new ArgumentNullException ("inner stream was disposed");
|
||||
|
||||
int buffer_length = count;
|
||||
|
||||
// partial block (in progress)
|
||||
if ((_partialCount > 0) && (_partialCount != _transform.InputBlockSize)) {
|
||||
int remainder = _transform.InputBlockSize - _partialCount;
|
||||
remainder = ((count < remainder) ? count : remainder);
|
||||
Buffer.BlockCopy (buffer, offset, _workingBlock, _partialCount, remainder);
|
||||
_partialCount += remainder;
|
||||
offset += remainder;
|
||||
count -= remainder;
|
||||
}
|
||||
|
||||
int bufferPos = offset;
|
||||
while (count > 0) {
|
||||
if (_partialCount == _transform.InputBlockSize) {
|
||||
if (_currentBlock == null)
|
||||
_currentBlock = new byte [_transform.OutputBlockSize];
|
||||
|
||||
// use partial block to avoid (re)allocation
|
||||
int len = _transform.TransformBlock (_workingBlock, 0, _partialCount, _currentBlock, 0);
|
||||
_stream.Write (_currentBlock, 0, len);
|
||||
// reset
|
||||
_partialCount = 0;
|
||||
}
|
||||
|
||||
if (_transform.CanTransformMultipleBlocks) {
|
||||
// get the biggest multiple of InputBlockSize in count (without mul or div)
|
||||
int size = (count & ~(_transform.InputBlockSize - 1));
|
||||
int rem = (count & (_transform.InputBlockSize - 1));
|
||||
// avoid reallocating memory at each call (reuse same buffer whenever possible)
|
||||
int sizeWorkingBlock = (1 + size / _transform.InputBlockSize) * _transform.OutputBlockSize;
|
||||
if (_workingBlock.Length < sizeWorkingBlock) {
|
||||
Array.Clear (_workingBlock, 0, _workingBlock.Length);
|
||||
_workingBlock = new byte [sizeWorkingBlock];
|
||||
}
|
||||
|
||||
if (size > 0) {
|
||||
int len = _transform.TransformBlock (buffer, offset, size, _workingBlock, 0);
|
||||
_stream.Write (_workingBlock, 0, len);
|
||||
}
|
||||
|
||||
if (rem > 0)
|
||||
Buffer.BlockCopy (buffer, buffer_length - rem, _workingBlock, 0, rem);
|
||||
_partialCount = rem;
|
||||
count = 0; // the last block, if any, is in _workingBlock
|
||||
} else {
|
||||
int len = Math.Min (_transform.InputBlockSize - _partialCount, count);
|
||||
Buffer.BlockCopy (buffer, bufferPos, _workingBlock, _partialCount, len);
|
||||
bufferPos += len;
|
||||
_partialCount += len;
|
||||
count -= len;
|
||||
// here block may be full, but we wont TransformBlock it until next iteration
|
||||
// so that the last block will be called in FlushFinalBlock using TransformFinalBlock
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public override void Flush ()
|
||||
{
|
||||
}
|
||||
|
||||
public void FlushFinalBlock ()
|
||||
{
|
||||
if (_flushedFinalBlock)
|
||||
throw new NotSupportedException (Locale.GetText ("This method cannot be called twice."));
|
||||
if (_disposed)
|
||||
throw new NotSupportedException (Locale.GetText ("CryptoStream was disposed."));
|
||||
|
||||
_flushedFinalBlock = true;
|
||||
byte[] finalBuffer = _transform.TransformFinalBlock (_workingBlock, 0, _partialCount);
|
||||
if (_stream != null && _mode == CryptoStreamMode.Write) {
|
||||
_stream.Write (finalBuffer, 0, finalBuffer.Length);
|
||||
}
|
||||
if (_stream is CryptoStream) {
|
||||
// for cascading crypto streams
|
||||
(_stream as CryptoStream).FlushFinalBlock ();
|
||||
} else {
|
||||
_stream.Flush ();
|
||||
}
|
||||
// zeroize
|
||||
Array.Clear (finalBuffer, 0, finalBuffer.Length);
|
||||
}
|
||||
|
||||
public override long Seek (long offset, SeekOrigin origin)
|
||||
{
|
||||
throw new NotSupportedException ("Seek");
|
||||
}
|
||||
|
||||
// LAMESPEC: Exception NotSupportedException not documented
|
||||
public override void SetLength (long value)
|
||||
{
|
||||
throw new NotSupportedException ("SetLength");
|
||||
}
|
||||
|
||||
protected override void Dispose (bool disposing)
|
||||
{
|
||||
if (!_disposed) {
|
||||
if (disposing) {
|
||||
if (!_flushedFinalBlock) {
|
||||
FlushFinalBlock ();
|
||||
}
|
||||
|
||||
if (_stream != null)
|
||||
_stream.Close ();
|
||||
}
|
||||
_disposed = true;
|
||||
// always cleared for security reason
|
||||
if (_workingBlock != null)
|
||||
Array.Clear (_workingBlock, 0, _workingBlock.Length);
|
||||
if (_currentBlock != null)
|
||||
Array.Clear (_currentBlock, 0, _currentBlock.Length);
|
||||
if (disposing) {
|
||||
_stream = null;
|
||||
_workingBlock = null;
|
||||
_currentBlock = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public bool HasFlushedFinalBlock {
|
||||
get { return _flushedFinalBlock; }
|
||||
}
|
||||
|
||||
public override Task FlushAsync (CancellationToken cancellationToken)
|
||||
{
|
||||
return base.FlushAsync (cancellationToken);
|
||||
}
|
||||
|
||||
public override Task<int> ReadAsync (byte[] buffer, int offset, int count, CancellationToken cancellationToken)
|
||||
{
|
||||
return base.ReadAsync (buffer, offset, count, cancellationToken);
|
||||
}
|
||||
|
||||
public override Task WriteAsync (byte[] buffer, int offset, int count, CancellationToken cancellationToken)
|
||||
{
|
||||
return base.WriteAsync (buffer, offset, count, cancellationToken);
|
||||
}
|
||||
}
|
||||
}
|
@ -1,41 +0,0 @@
|
||||
//
|
||||
// System.Security.Cryptography CryptoStreamMode enumeration
|
||||
//
|
||||
// Authors:
|
||||
// Matthew S. Ford (Matthew.S.Ford@Rose-Hulman.Edu)
|
||||
//
|
||||
// Copyright 2001 by authors.
|
||||
// Copyright (C) 2004-2005 Novell, Inc (http://www.novell.com)
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining
|
||||
// a copy of this software and associated documentation files (the
|
||||
// "Software"), to deal in the Software without restriction, including
|
||||
// without limitation the rights to use, copy, modify, merge, publish,
|
||||
// distribute, sublicense, and/or sell copies of the Software, and to
|
||||
// permit persons to whom the Software is furnished to do so, subject to
|
||||
// the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be
|
||||
// included in all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
namespace System.Security.Cryptography {
|
||||
|
||||
[Serializable]
|
||||
[ComVisible (true)]
|
||||
public enum CryptoStreamMode {
|
||||
Read,
|
||||
Write
|
||||
}
|
||||
}
|
||||
|
@ -1,76 +0,0 @@
|
||||
//
|
||||
// System.Security.Cryptography.CryptographicException.cs
|
||||
//
|
||||
// Authors:
|
||||
// Thomas Neidhart (tome@sbox.tugraz.at)
|
||||
// Sebastien Pouliot <sebastien@ximian.com>
|
||||
//
|
||||
// Copyright (C) 2004-2005 Novell, Inc (http://www.novell.com)
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining
|
||||
// a copy of this software and associated documentation files (the
|
||||
// "Software"), to deal in the Software without restriction, including
|
||||
// without limitation the rights to use, copy, modify, merge, publish,
|
||||
// distribute, sublicense, and/or sell copies of the Software, and to
|
||||
// permit persons to whom the Software is furnished to do so, subject to
|
||||
// the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be
|
||||
// included in all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
using System;
|
||||
using System.Globalization;
|
||||
using System.Runtime.Serialization;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
namespace System.Security.Cryptography {
|
||||
|
||||
[Serializable]
|
||||
[ComVisible (true)]
|
||||
public class CryptographicException : SystemException, _Exception {
|
||||
public CryptographicException ()
|
||||
: base (Locale.GetText ("Error occurred during a cryptographic operation."))
|
||||
{
|
||||
// default to CORSEC_E_CRYPTO
|
||||
// defined as EMAKEHR(0x1430) in CorError.h
|
||||
HResult = unchecked ((int)0x80131430);
|
||||
}
|
||||
|
||||
public CryptographicException (int hr)
|
||||
{
|
||||
HResult = hr;
|
||||
}
|
||||
|
||||
public CryptographicException (string message)
|
||||
: base (message)
|
||||
{
|
||||
HResult = unchecked ((int)0x80131430);
|
||||
}
|
||||
|
||||
public CryptographicException (string message, Exception inner)
|
||||
: base (message, inner)
|
||||
{
|
||||
HResult = unchecked ((int)0x80131430);
|
||||
}
|
||||
|
||||
public CryptographicException (string format, string insert)
|
||||
: base (String.Format (format, insert))
|
||||
{
|
||||
HResult = unchecked ((int)0x80131430);
|
||||
}
|
||||
|
||||
protected CryptographicException (SerializationInfo info, StreamingContext context)
|
||||
: base (info, context)
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
@ -1,70 +0,0 @@
|
||||
//
|
||||
// System.Security.Cryptography.CryptographicUnexpectedOperationException.cs
|
||||
//
|
||||
// Authors:
|
||||
// Thomas Neidhart (tome@sbox.tugraz.at)
|
||||
// Sebastien Pouliot <sebastien@ximian.com>
|
||||
//
|
||||
// Copyright (C) 2004-2005 Novell, Inc (http://www.novell.com)
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining
|
||||
// a copy of this software and associated documentation files (the
|
||||
// "Software"), to deal in the Software without restriction, including
|
||||
// without limitation the rights to use, copy, modify, merge, publish,
|
||||
// distribute, sublicense, and/or sell copies of the Software, and to
|
||||
// permit persons to whom the Software is furnished to do so, subject to
|
||||
// the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be
|
||||
// included in all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
using System.Globalization;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Runtime.Serialization;
|
||||
|
||||
namespace System.Security.Cryptography {
|
||||
|
||||
[Serializable]
|
||||
[ComVisible (true)]
|
||||
public class CryptographicUnexpectedOperationException : CryptographicException {
|
||||
|
||||
public CryptographicUnexpectedOperationException ()
|
||||
: base (Locale.GetText ("Unexpected error occurred during a cryptographic operation."))
|
||||
{
|
||||
// Default to CORSEC_E_CRYPTO_UNEX_OPER (CorError.h)
|
||||
HResult = unchecked ((int)0x80131431);
|
||||
}
|
||||
|
||||
public CryptographicUnexpectedOperationException (string message)
|
||||
: base (message)
|
||||
{
|
||||
HResult = unchecked ((int)0x80131431);
|
||||
}
|
||||
|
||||
public CryptographicUnexpectedOperationException (string message, Exception inner)
|
||||
: base (message, inner)
|
||||
{
|
||||
HResult = unchecked ((int)0x80131431);
|
||||
}
|
||||
|
||||
public CryptographicUnexpectedOperationException (string format, string insert)
|
||||
: base (String.Format(format, insert))
|
||||
{
|
||||
HResult = unchecked ((int)0x80131431);
|
||||
}
|
||||
|
||||
protected CryptographicUnexpectedOperationException (SerializationInfo info, StreamingContext context)
|
||||
: base (info, context)
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
@ -1,127 +0,0 @@
|
||||
//
|
||||
// System.Security.Cryptography.CspParameters.cs
|
||||
//
|
||||
// Authors:
|
||||
// Thomas Neidhart (tome@sbox.tugraz.at)
|
||||
// Sebastien Pouliot <sebastien@ximian.com>
|
||||
//
|
||||
// Copyright (C) 2004-2005 Novell, Inc (http://www.novell.com)
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining
|
||||
// a copy of this software and associated documentation files (the
|
||||
// "Software"), to deal in the Software without restriction, including
|
||||
// without limitation the rights to use, copy, modify, merge, publish,
|
||||
// distribute, sublicense, and/or sell copies of the Software, and to
|
||||
// permit persons to whom the Software is furnished to do so, subject to
|
||||
// the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be
|
||||
// included in all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Security.AccessControl;
|
||||
|
||||
namespace System.Security.Cryptography {
|
||||
|
||||
[ComVisible (true)]
|
||||
public sealed class CspParameters {
|
||||
|
||||
private CspProviderFlags _Flags;
|
||||
|
||||
public CspParameters ()
|
||||
: this (1)
|
||||
{
|
||||
}
|
||||
|
||||
public CspParameters (int dwTypeIn)
|
||||
: this (dwTypeIn, null)
|
||||
{
|
||||
}
|
||||
|
||||
public CspParameters (int dwTypeIn, string strProviderNameIn)
|
||||
: this (dwTypeIn, null, null)
|
||||
{
|
||||
}
|
||||
|
||||
public CspParameters (int dwTypeIn, string strProviderNameIn, string strContainerNameIn)
|
||||
{
|
||||
ProviderType = dwTypeIn;
|
||||
ProviderName = strProviderNameIn;
|
||||
KeyContainerName = strContainerNameIn;
|
||||
|
||||
// not defined in specs, only tested from M$ impl
|
||||
KeyNumber = -1;
|
||||
}
|
||||
|
||||
public string KeyContainerName;
|
||||
|
||||
public int KeyNumber;
|
||||
|
||||
public string ProviderName;
|
||||
|
||||
public int ProviderType;
|
||||
|
||||
public CspProviderFlags Flags {
|
||||
get { return _Flags; }
|
||||
set { _Flags = value; }
|
||||
}
|
||||
|
||||
private SecureString _password;
|
||||
private IntPtr _windowHandle;
|
||||
|
||||
public CspParameters (int providerType, string providerName, string keyContainerName,
|
||||
CryptoKeySecurity cryptoKeySecurity, IntPtr parentWindowHandle)
|
||||
: this (providerType, providerName, keyContainerName)
|
||||
{
|
||||
if (cryptoKeySecurity != null)
|
||||
CryptoKeySecurity = cryptoKeySecurity;
|
||||
_windowHandle = parentWindowHandle;
|
||||
}
|
||||
|
||||
public CspParameters (int providerType, string providerName, string keyContainerName,
|
||||
CryptoKeySecurity cryptoKeySecurity, SecureString keyPassword)
|
||||
: this (providerType, providerName, keyContainerName)
|
||||
{
|
||||
if (cryptoKeySecurity != null)
|
||||
CryptoKeySecurity = cryptoKeySecurity;
|
||||
_password = keyPassword;
|
||||
}
|
||||
|
||||
internal CspParameters(CspParameters parameters)
|
||||
: this(parameters.ProviderType, parameters.ProviderName, parameters.KeyContainerName)
|
||||
{
|
||||
if (parameters.CryptoKeySecurity != null)
|
||||
CryptoKeySecurity = parameters.CryptoKeySecurity;
|
||||
|
||||
_Flags = parameters.Flags;
|
||||
KeyNumber = parameters.KeyNumber;
|
||||
_password = parameters.KeyPassword;
|
||||
_windowHandle = parameters.ParentWindowHandle;
|
||||
}
|
||||
|
||||
[MonoTODO ("access control isn't implemented")]
|
||||
public CryptoKeySecurity CryptoKeySecurity {
|
||||
get { throw new NotImplementedException (); }
|
||||
set { throw new NotImplementedException (); }
|
||||
}
|
||||
|
||||
public SecureString KeyPassword {
|
||||
get { return _password; }
|
||||
set { _password = value; }
|
||||
}
|
||||
|
||||
public IntPtr ParentWindowHandle {
|
||||
get { return _windowHandle; }
|
||||
set { _windowHandle = value; }
|
||||
}
|
||||
}
|
||||
}
|
@ -1,49 +0,0 @@
|
||||
//
|
||||
// System.Security.Cryptography CspProviderFlags enumeration
|
||||
//
|
||||
// Authors:
|
||||
// Thomas Neidhart <tome@sbox.tugraz.at>
|
||||
// Sebastien Pouliot <sebastien@ximian.com>
|
||||
//
|
||||
// Copyright (C) 2004-2005, 2011 Novell, Inc (http://www.novell.com)
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining
|
||||
// a copy of this software and associated documentation files (the
|
||||
// "Software"), to deal in the Software without restriction, including
|
||||
// without limitation the rights to use, copy, modify, merge, publish,
|
||||
// distribute, sublicense, and/or sell copies of the Software, and to
|
||||
// permit persons to whom the Software is furnished to do so, subject to
|
||||
// the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be
|
||||
// included in all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
namespace System.Security.Cryptography {
|
||||
|
||||
[Flags]
|
||||
[Serializable]
|
||||
[ComVisible (true)]
|
||||
public enum CspProviderFlags {
|
||||
UseMachineKeyStore = 1,
|
||||
UseDefaultKeyContainer = 2,
|
||||
UseExistingKey = 8,
|
||||
NoFlags = 0,
|
||||
NoPrompt = 64,
|
||||
UseArchivableKey = 16,
|
||||
UseNonExportableKey = 4,
|
||||
UseUserProtectedKey = 32,
|
||||
CreateEphemeralKey = 128
|
||||
}
|
||||
}
|
||||
|
@ -1,188 +0,0 @@
|
||||
//
|
||||
// System.Security.Cryptography.DES.cs
|
||||
//
|
||||
// Author:
|
||||
// Sergey Chaban (serge@wildwestsoftware.com)
|
||||
// Sebastien Pouliot <sebastien@ximian.com>
|
||||
//
|
||||
// Portions (C) 2002 Motus Technologies Inc. (http://www.motus.com)
|
||||
// Copyright (C) 2004-2006 Novell, Inc (http://www.novell.com)
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining
|
||||
// a copy of this software and associated documentation files (the
|
||||
// "Software"), to deal in the Software without restriction, including
|
||||
// without limitation the rights to use, copy, modify, merge, publish,
|
||||
// distribute, sublicense, and/or sell copies of the Software, and to
|
||||
// permit persons to whom the Software is furnished to do so, subject to
|
||||
// the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be
|
||||
// included in all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
using System.Globalization;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
// References:
|
||||
// a. FIPS PUB 46-3: Data Encryption Standard
|
||||
// http://csrc.nist.gov/publications/fips/fips46-3/fips46-3.pdf
|
||||
|
||||
namespace System.Security.Cryptography {
|
||||
|
||||
[ComVisible (true)]
|
||||
public abstract class DES : SymmetricAlgorithm {
|
||||
|
||||
private const int keySizeByte = 8;
|
||||
|
||||
protected DES ()
|
||||
{
|
||||
KeySizeValue = 64;
|
||||
BlockSizeValue = 64;
|
||||
FeedbackSizeValue = 8;
|
||||
|
||||
LegalKeySizesValue = new KeySizes[1];
|
||||
LegalKeySizesValue[0] = new KeySizes(64, 64, 0);
|
||||
|
||||
LegalBlockSizesValue = new KeySizes[1];
|
||||
LegalBlockSizesValue[0] = new KeySizes(64, 64, 0);
|
||||
}
|
||||
|
||||
public static new DES Create ()
|
||||
{
|
||||
#if FULL_AOT_RUNTIME
|
||||
return new System.Security.Cryptography.DESCryptoServiceProvider ();
|
||||
#else
|
||||
return Create ("System.Security.Cryptography.DES");
|
||||
#endif
|
||||
}
|
||||
|
||||
public static new DES Create (string algName)
|
||||
{
|
||||
return (DES) CryptoConfig.CreateFromName (algName);
|
||||
}
|
||||
|
||||
|
||||
// Ek(Ek(m)) = m
|
||||
internal static readonly byte[,] weakKeys = {
|
||||
{ 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01 },
|
||||
{ 0x1F, 0x1F, 0x1F, 0x1F, 0x0F, 0x0F, 0x0F, 0x0F },
|
||||
{ 0xE1, 0xE1, 0xE1, 0xE1, 0xF1, 0xF1, 0xF1, 0xF1 },
|
||||
{ 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF },
|
||||
};
|
||||
|
||||
// Ek1(Ek2(m)) = m
|
||||
internal static readonly byte[,] semiWeakKeys = {
|
||||
{ 0x00, 0x1E, 0x00, 0x1E, 0x00, 0x0E, 0x00, 0x0E }, // map to packed key 011F011F010E010E
|
||||
{ 0x00, 0xE0, 0x00, 0xE0, 0x00, 0xF0, 0x00, 0xF0 }, // map to packed key 01E001E001F101F1
|
||||
{ 0x00, 0xFE, 0x00, 0xFE, 0x00, 0xFE, 0x00, 0xFE }, // map to packed key 01FE01FE01FE01FE
|
||||
{ 0x1E, 0x00, 0x1E, 0x00, 0x0E, 0x00, 0x0E, 0x00 }, // map to packed key 1F011F010E010E01
|
||||
{ 0x1E, 0xE0, 0x1E, 0xE0, 0x0E, 0xF0, 0x0E, 0xF0 }, // map to packed key 1FE01FE00EF10EF1
|
||||
{ 0x1E, 0xFE, 0x1E, 0xFE, 0x0E, 0xFE, 0x0E, 0xFE }, // map to packed key 1FFE1FFE0EFE0EFE
|
||||
{ 0xE0, 0x00, 0xE0, 0x00, 0xF0, 0x00, 0xF0, 0x00 }, // map to packed key E001E001F101F101
|
||||
{ 0xE0, 0x1E, 0xE0, 0x1E, 0xF0, 0x0E, 0xF0, 0x0E }, // map to packed key E01FE01FF10EF10E
|
||||
{ 0xE0, 0xFE, 0xE0, 0xFE, 0xF0, 0xFE, 0xF0, 0xFE }, // map to packed key E0FEE0FEF1FEF1FE
|
||||
{ 0xFE, 0x00, 0xFE, 0x00, 0xFE, 0x00, 0xFE, 0x00 }, // map to packed key FE01FE01FE01FE01
|
||||
{ 0xFE, 0x1E, 0xFE, 0x1E, 0xFE, 0x0E, 0xFE, 0x0E }, // map to packed key FE1FFE1FFE0EFE0E
|
||||
{ 0xFE, 0xE0, 0xFE, 0xE0, 0xFE, 0xF0, 0xFE, 0xF0 }, // map to packed key FEE0FEE0FEF1FEF1
|
||||
};
|
||||
|
||||
public static bool IsWeakKey (byte[] rgbKey)
|
||||
{
|
||||
if (rgbKey == null)
|
||||
throw new CryptographicException (Locale.GetText ("Null Key"));
|
||||
if (rgbKey.Length != keySizeByte)
|
||||
throw new CryptographicException (Locale.GetText ("Wrong Key Length"));
|
||||
|
||||
// (fast) pre-check with "weak bytes"
|
||||
for (int i=0; i < rgbKey.Length; i++) {
|
||||
switch (rgbKey [i] | 0x11) {
|
||||
case 0x11:
|
||||
case 0x1F:
|
||||
case 0xF1:
|
||||
case 0xFF:
|
||||
break;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
// compare with known weak keys
|
||||
for (int i=0; i < (weakKeys.Length >> 3); i++) {
|
||||
int j = 0;
|
||||
for (; j < rgbKey.Length; j++) {
|
||||
if ((rgbKey [j] ^ weakKeys [i,j]) > 1)
|
||||
break;
|
||||
}
|
||||
if (j==8)
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public static bool IsSemiWeakKey (byte[] rgbKey)
|
||||
{
|
||||
if (rgbKey == null)
|
||||
throw new CryptographicException (Locale.GetText ("Null Key"));
|
||||
if (rgbKey.Length != keySizeByte)
|
||||
throw new CryptographicException (Locale.GetText ("Wrong Key Length"));
|
||||
|
||||
// (fast) pre-check with "weak bytes"
|
||||
for (int i=0; i < rgbKey.Length; i++) {
|
||||
switch (rgbKey [i] | 0x11) {
|
||||
case 0x11:
|
||||
case 0x1F:
|
||||
case 0xF1:
|
||||
case 0xFF:
|
||||
break;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
// compare with known weak keys
|
||||
for (int i=0; i < (semiWeakKeys.Length >> 3); i++) {
|
||||
int j = 0;
|
||||
for (; j < rgbKey.Length; j++) {
|
||||
if ((rgbKey [j] ^ semiWeakKeys [i,j]) > 1)
|
||||
break;
|
||||
}
|
||||
if (j==8)
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public override byte[] Key {
|
||||
get {
|
||||
if (KeyValue == null) {
|
||||
// GenerateKey is responsible to return a valid key
|
||||
// e.g. no weak or semi-weak keys
|
||||
GenerateKey ();
|
||||
}
|
||||
return (byte[]) KeyValue.Clone ();
|
||||
}
|
||||
set {
|
||||
if (value == null)
|
||||
throw new ArgumentNullException ("Key");
|
||||
if (value.Length != keySizeByte)
|
||||
throw new ArgumentException (Locale.GetText ("Wrong Key Length"));
|
||||
if (IsWeakKey (value))
|
||||
throw new CryptographicException (Locale.GetText ("Weak Key"));
|
||||
if (IsSemiWeakKey (value))
|
||||
throw new CryptographicException (Locale.GetText ("Semi Weak Key"));
|
||||
|
||||
KeyValue = (byte[]) value.Clone ();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -655,34 +655,6 @@ namespace System.Security.Cryptography {
|
||||
key = KeyBuilder.Key (DESTransform.KEY_BYTE_SIZE);
|
||||
return key;
|
||||
}
|
||||
}
|
||||
|
||||
[ComVisible (true)]
|
||||
public sealed class DESCryptoServiceProvider : DES {
|
||||
|
||||
public DESCryptoServiceProvider ()
|
||||
{
|
||||
}
|
||||
|
||||
public override ICryptoTransform CreateDecryptor (byte[] rgbKey, byte[] rgbIV)
|
||||
{
|
||||
return new DESTransform (this, false, rgbKey, rgbIV);
|
||||
}
|
||||
|
||||
public override ICryptoTransform CreateEncryptor (byte[] rgbKey, byte[] rgbIV)
|
||||
{
|
||||
return new DESTransform (this, true, rgbKey, rgbIV);
|
||||
}
|
||||
|
||||
public override void GenerateIV ()
|
||||
{
|
||||
IVValue = KeyBuilder.IV (DESTransform.BLOCK_BYTE_SIZE);
|
||||
}
|
||||
|
||||
public override void GenerateKey ()
|
||||
{
|
||||
KeyValue = DESTransform.GetStrongKey ();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1,182 +0,0 @@
|
||||
//
|
||||
// System.Security.Cryptography.DSA.cs class implementation
|
||||
//
|
||||
// Authors:
|
||||
// Thomas Neidhart (tome@sbox.tugraz.at)
|
||||
// Sebastien Pouliot (sebastien@ximian.com)
|
||||
//
|
||||
// Portions (C) 2002, 2003 Motus Technologies Inc. (http://www.motus.com)
|
||||
// Copyright (C) 2004-2005, 2008 Novell, Inc (http://www.novell.com)
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining
|
||||
// a copy of this software and associated documentation files (the
|
||||
// "Software"), to deal in the Software without restriction, including
|
||||
// without limitation the rights to use, copy, modify, merge, publish,
|
||||
// distribute, sublicense, and/or sell copies of the Software, and to
|
||||
// permit persons to whom the Software is furnished to do so, subject to
|
||||
// the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be
|
||||
// included in all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
using System.Globalization;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Text;
|
||||
|
||||
using Mono.Xml;
|
||||
using Mono.Security;
|
||||
|
||||
// References:
|
||||
// a. FIPS PUB 186-2: Digital Signature Standard (DSS)
|
||||
// http://csrc.nist.gov/publications/fips/fips186-2/fips186-2-change1.pdf
|
||||
|
||||
namespace System.Security.Cryptography {
|
||||
|
||||
[ComVisible (true)]
|
||||
public abstract class DSA : AsymmetricAlgorithm {
|
||||
|
||||
// Constructor visibility fixed in Fx 2.0
|
||||
protected DSA ()
|
||||
{
|
||||
}
|
||||
|
||||
public static new DSA Create ()
|
||||
{
|
||||
#if FULL_AOT_RUNTIME
|
||||
return new System.Security.Cryptography.DSACryptoServiceProvider ();
|
||||
#else
|
||||
return Create ("System.Security.Cryptography.DSA");
|
||||
#endif
|
||||
}
|
||||
|
||||
public static new DSA Create (string algName)
|
||||
{
|
||||
return (DSA) CryptoConfig.CreateFromName (algName);
|
||||
}
|
||||
|
||||
public abstract byte[] CreateSignature (byte[] rgbHash);
|
||||
|
||||
public abstract DSAParameters ExportParameters (bool includePrivateParameters);
|
||||
|
||||
internal void ZeroizePrivateKey (DSAParameters parameters)
|
||||
{
|
||||
if (parameters.X != null)
|
||||
Array.Clear (parameters.X, 0, parameters.X.Length);
|
||||
}
|
||||
|
||||
public override void FromXmlString (string xmlString)
|
||||
{
|
||||
if (xmlString == null)
|
||||
throw new ArgumentNullException ("xmlString");
|
||||
|
||||
DSAParameters dsaParams = new DSAParameters ();
|
||||
try {
|
||||
dsaParams.P = GetNamedParam (xmlString, "P");
|
||||
dsaParams.Q = GetNamedParam (xmlString, "Q");
|
||||
dsaParams.G = GetNamedParam (xmlString, "G");
|
||||
dsaParams.J = GetNamedParam (xmlString, "J");
|
||||
dsaParams.Y = GetNamedParam (xmlString, "Y");
|
||||
dsaParams.X = GetNamedParam (xmlString, "X");
|
||||
dsaParams.Seed = GetNamedParam (xmlString, "Seed");
|
||||
byte[] counter = GetNamedParam (xmlString, "PgenCounter");
|
||||
if (counter != null) {
|
||||
byte[] counter4b = new byte [4]; // always 4 bytes
|
||||
Buffer.BlockCopy (counter, 0, counter4b, 0, counter.Length);
|
||||
dsaParams.Counter = BitConverterLE.ToInt32 (counter4b, 0);
|
||||
}
|
||||
ImportParameters (dsaParams);
|
||||
}
|
||||
catch {
|
||||
ZeroizePrivateKey (dsaParams);
|
||||
throw;
|
||||
}
|
||||
finally {
|
||||
ZeroizePrivateKey (dsaParams);
|
||||
}
|
||||
}
|
||||
|
||||
public abstract void ImportParameters (DSAParameters parameters);
|
||||
|
||||
// note: using SecurityElement.ToXml wouldn't generate the same string as the MS implementation
|
||||
public override string ToXmlString (bool includePrivateParameters)
|
||||
{
|
||||
StringBuilder sb = new StringBuilder ();
|
||||
DSAParameters dsaParams = ExportParameters (includePrivateParameters);
|
||||
try {
|
||||
sb.Append ("<DSAKeyValue>");
|
||||
|
||||
sb.Append ("<P>");
|
||||
sb.Append (Convert.ToBase64String (dsaParams.P));
|
||||
sb.Append ("</P>");
|
||||
|
||||
sb.Append ("<Q>");
|
||||
sb.Append (Convert.ToBase64String (dsaParams.Q));
|
||||
sb.Append ("</Q>");
|
||||
|
||||
sb.Append ("<G>");
|
||||
sb.Append (Convert.ToBase64String (dsaParams.G));
|
||||
sb.Append ("</G>");
|
||||
|
||||
sb.Append ("<Y>");
|
||||
sb.Append (Convert.ToBase64String (dsaParams.Y));
|
||||
sb.Append( "</Y>");
|
||||
|
||||
if (dsaParams.J != null) {
|
||||
// if J wasn't imported then it's not exported and neither
|
||||
// is part of the XML output
|
||||
sb.Append ("<J>");
|
||||
sb.Append (Convert.ToBase64String (dsaParams.J));
|
||||
sb.Append ("</J>");
|
||||
}
|
||||
|
||||
if (dsaParams.Seed != null) {
|
||||
sb.Append ("<Seed>");
|
||||
sb.Append (Convert.ToBase64String (dsaParams.Seed));
|
||||
sb.Append ("</Seed>");
|
||||
|
||||
sb.Append ("<PgenCounter>");
|
||||
// the number of bytes is important (no matter == 0x00)
|
||||
if (dsaParams.Counter != 0) {
|
||||
byte[] inArr = BitConverterLE.GetBytes (dsaParams.Counter);
|
||||
int l = inArr.Length;
|
||||
while (inArr[l-1] == 0x00)
|
||||
l--;
|
||||
|
||||
sb.Append (Convert.ToBase64String (inArr, 0, l));
|
||||
} else {
|
||||
sb.Append ("AA=="); // base64 encoded 0
|
||||
}
|
||||
sb.Append ("</PgenCounter>");
|
||||
}
|
||||
|
||||
if (dsaParams.X != null) {
|
||||
sb.Append ("<X>");
|
||||
sb.Append (Convert.ToBase64String (dsaParams.X));
|
||||
sb.Append ("</X>");
|
||||
}
|
||||
else if (includePrivateParameters) {
|
||||
throw new ArgumentNullException ("X");
|
||||
}
|
||||
|
||||
sb.Append ("</DSAKeyValue>");
|
||||
}
|
||||
catch {
|
||||
ZeroizePrivateKey (dsaParams);
|
||||
throw;
|
||||
}
|
||||
|
||||
return sb.ToString ();
|
||||
}
|
||||
|
||||
public abstract bool VerifySignature (byte[] rgbHash, byte[] rgbSignature);
|
||||
}
|
||||
}
|
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user