mirror of
https://github.com/opensim/opensim.git
synced 2026-08-11 11:57:03 +08:00
break them a bit more...
This commit is contained in:
@@ -1368,13 +1368,13 @@ namespace OpenSim.Framework
|
|||||||
}
|
}
|
||||||
|
|
||||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||||
public static string AESEncrypt(string secret, string plainText)
|
public static string AESEncrypt(ReadOnlySpan<char> secret, ReadOnlySpan<char> plainText)
|
||||||
{
|
{
|
||||||
return AESEncryptString(secret, plainText, string.Empty);
|
return AESEncryptString(secret, plainText, string.Empty);
|
||||||
}
|
}
|
||||||
|
|
||||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||||
public static string AESEncryptTo(string secret, string plainText, string ivString)
|
public static string AESEncryptTo(ReadOnlySpan<char> secret, ReadOnlySpan<char> plainText, ReadOnlySpan<char> ivString)
|
||||||
{
|
{
|
||||||
return AESEncryptString(secret, plainText, ivString);
|
return AESEncryptString(secret, plainText, ivString);
|
||||||
}
|
}
|
||||||
@@ -1388,15 +1388,15 @@ namespace OpenSim.Framework
|
|||||||
/// ID...</param>
|
/// ID...</param>
|
||||||
/// <returns>A string composed by the Initialization Vector bytes and the
|
/// <returns>A string composed by the Initialization Vector bytes and the
|
||||||
/// encrypted text bytes converted to lower case HexString and separated by " : " </returns>
|
/// encrypted text bytes converted to lower case HexString and separated by " : " </returns>
|
||||||
private static string AESEncryptString(string secret, string plainText, string ivString = null)
|
private static string AESEncryptString(ReadOnlySpan<char> secret, ReadOnlySpan<char> plainText, ReadOnlySpan<char> ivString)
|
||||||
{
|
{
|
||||||
if(string.IsNullOrEmpty(secret) || string.IsNullOrEmpty(plainText))
|
if(secret.Length == 0 || plainText.Length == 0)
|
||||||
return string.Empty;
|
return string.Empty;
|
||||||
|
|
||||||
byte[] iv = string.IsNullOrEmpty(ivString) ?
|
byte[] iv = ivString.Length == 0 ?
|
||||||
MD5.Create().ComputeHash(UUID.Random().GetBytes()) :
|
MD5.Create().ComputeHash(UUID.Random().GetBytes()) :
|
||||||
MD5.Create().ComputeHash(Encoding.UTF8.GetBytes(ivString));
|
MD5.Create().ComputeHash(Utils.StringToBytesNoTerm(ivString));
|
||||||
byte[] aesKey = SHA256.Create().ComputeHash(Encoding.UTF8.GetBytes(secret));
|
byte[] aesKey = SHA256.Create().ComputeHash(Utils.StringToBytesNoTerm(secret));
|
||||||
byte[] encryptedText;
|
byte[] encryptedText;
|
||||||
|
|
||||||
using (Aes aes = Aes.Create())
|
using (Aes aes = Aes.Create())
|
||||||
@@ -1419,13 +1419,13 @@ namespace OpenSim.Framework
|
|||||||
}
|
}
|
||||||
|
|
||||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||||
public static string AESDecrypt(string secret, string encryptedText)
|
public static ReadOnlySpan<char> AESDecrypt(ReadOnlySpan<char> secret, ReadOnlySpan<char> encryptedText)
|
||||||
{
|
{
|
||||||
return AESDecryptString(secret, encryptedText, string.Empty);
|
return AESDecryptString(secret, encryptedText, new ReadOnlySpan<char>());
|
||||||
}
|
}
|
||||||
|
|
||||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||||
public static string AESDecryptFrom(string secret, string encryptedText, string ivString)
|
public static ReadOnlySpan<char> AESDecryptFrom(ReadOnlySpan<char> secret, ReadOnlySpan<char> encryptedText, ReadOnlySpan<char> ivString)
|
||||||
{
|
{
|
||||||
return AESDecryptString(secret, encryptedText, ivString);
|
return AESDecryptString(secret, encryptedText, ivString);
|
||||||
}
|
}
|
||||||
@@ -1440,31 +1440,30 @@ namespace OpenSim.Framework
|
|||||||
/// if used in the encription. eg; an avatarID, a SecureSessionID, an object or
|
/// if used in the encription. eg; an avatarID, a SecureSessionID, an object or
|
||||||
/// script ID...</param>
|
/// script ID...</param>
|
||||||
/// <returns>The decrypted string.</returns>
|
/// <returns>The decrypted string.</returns>
|
||||||
private static string AESDecryptString(string secret, string encryptedText, string ivString = null)
|
private static ReadOnlySpan<char> AESDecryptString(ReadOnlySpan<char> secret, ReadOnlySpan<char> encryptedText, ReadOnlySpan<char> ivString)
|
||||||
{
|
{
|
||||||
if(string.IsNullOrEmpty(secret) || string.IsNullOrEmpty(encryptedText))
|
if(secret.Length == 0 || encryptedText.Length == 0)
|
||||||
return string.Empty;
|
return string.Empty;
|
||||||
|
|
||||||
string[] encodedParts = encryptedText.Split(":");
|
int sep = encryptedText.IndexOf(':');
|
||||||
if(encodedParts.Length < 2 || encodedParts[1].Length == 0)
|
if(sep < 0)
|
||||||
return string.Empty;
|
return string.Empty;
|
||||||
|
|
||||||
byte[] iv;
|
byte[] iv;
|
||||||
byte[] buffer;
|
byte[] buffer;
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
iv = string.IsNullOrEmpty(ivString) ?
|
iv = ivString.Length == 0 ?
|
||||||
Convert.FromHexString(encodedParts[0]) :
|
Convert.FromHexString(encryptedText[..sep]):
|
||||||
MD5.Create().ComputeHash(Encoding.UTF8.GetBytes(ivString));
|
MD5.Create().ComputeHash(Utils.StringToBytesNoTerm(ivString));
|
||||||
|
buffer = Convert.FromHexString(encryptedText[(sep + 1)..]);
|
||||||
buffer = Convert.FromHexString(encodedParts[1]);
|
|
||||||
}
|
}
|
||||||
catch
|
catch
|
||||||
{
|
{
|
||||||
return string.Empty;
|
return string.Empty;
|
||||||
}
|
}
|
||||||
|
|
||||||
byte[] aesKey = SHA256.Create().ComputeHash(Encoding.UTF8.GetBytes(secret));
|
byte[] aesKey = SHA256.Create().ComputeHash(Utils.StringToBytesNoTerm(secret));
|
||||||
|
|
||||||
using Aes aes = Aes.Create();
|
using Aes aes = Aes.Create();
|
||||||
aes.Key = aesKey;
|
aes.Key = aesKey;
|
||||||
|
|||||||
@@ -6380,13 +6380,13 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
|
|||||||
if(string.IsNullOrEmpty(secret) || string.IsNullOrEmpty(plainText))
|
if(string.IsNullOrEmpty(secret) || string.IsNullOrEmpty(plainText))
|
||||||
return LSL_String.Empty;
|
return LSL_String.Empty;
|
||||||
|
|
||||||
string ret = Util.AESEncrypt(secret, plainText);
|
ReadOnlySpan<char> ret = Util.AESEncrypt(secret.AsSpan(), plainText.AsSpan());
|
||||||
if(string.IsNullOrEmpty(ret))
|
if(ret.Length == 0)
|
||||||
{
|
{
|
||||||
OSSLShoutError("osAESEncrypt: Failed to encrypt!");
|
OSSLShoutError("osAESEncrypt: Failed to encrypt!");
|
||||||
return LSL_String.Empty;
|
return LSL_String.Empty;
|
||||||
}
|
}
|
||||||
return ret;
|
return ret.ToString();
|
||||||
}
|
}
|
||||||
|
|
||||||
public LSL_String osAESDecrypt(string secret, string encryptedText)
|
public LSL_String osAESDecrypt(string secret, string encryptedText)
|
||||||
@@ -6394,13 +6394,13 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
|
|||||||
if(string.IsNullOrEmpty(secret) || string.IsNullOrEmpty(encryptedText))
|
if(string.IsNullOrEmpty(secret) || string.IsNullOrEmpty(encryptedText))
|
||||||
return LSL_String.Empty;
|
return LSL_String.Empty;
|
||||||
|
|
||||||
string ret = Util.AESDecrypt(secret, encryptedText);
|
ReadOnlySpan<char> ret = Util.AESDecrypt(secret.AsSpan(), encryptedText.AsSpan());
|
||||||
if(string.IsNullOrEmpty(ret))
|
if(ret.Length == 0)
|
||||||
{
|
{
|
||||||
OSSLShoutError("osAESDecrypt: Failed to Decrypt!");
|
OSSLShoutError("osAESDecrypt: Failed to Decrypt!");
|
||||||
return LSL_String.Empty;
|
return LSL_String.Empty;
|
||||||
}
|
}
|
||||||
return ret;
|
return ret.ToString();
|
||||||
}
|
}
|
||||||
|
|
||||||
public LSL_String osAESEncryptTo(string secret, string plainText, string ivString)
|
public LSL_String osAESEncryptTo(string secret, string plainText, string ivString)
|
||||||
@@ -6408,13 +6408,13 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
|
|||||||
if(string.IsNullOrEmpty(secret) || string.IsNullOrEmpty(plainText) || string.IsNullOrEmpty(ivString))
|
if(string.IsNullOrEmpty(secret) || string.IsNullOrEmpty(plainText) || string.IsNullOrEmpty(ivString))
|
||||||
return LSL_String.Empty;
|
return LSL_String.Empty;
|
||||||
|
|
||||||
string ret = Util.AESEncryptTo(secret, plainText, ivString);
|
ReadOnlySpan<char> ret = Util.AESEncryptTo(secret.AsSpan(), plainText.AsSpan(), ivString.AsSpan());
|
||||||
if(string.IsNullOrEmpty(ret))
|
if (ret.Length == 0)
|
||||||
{
|
{
|
||||||
OSSLShoutError("osAESEncryptTo: Failed to encrypt!");
|
OSSLShoutError("osAESEncryptTo: Failed to encrypt!");
|
||||||
return LSL_String.Empty;
|
return LSL_String.Empty;
|
||||||
}
|
}
|
||||||
return ret;
|
return ret.ToString();
|
||||||
}
|
}
|
||||||
|
|
||||||
public LSL_String osAESDecryptFrom(string secret, string encryptedText, string ivString)
|
public LSL_String osAESDecryptFrom(string secret, string encryptedText, string ivString)
|
||||||
@@ -6422,13 +6422,13 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
|
|||||||
if(string.IsNullOrEmpty(secret) || string.IsNullOrEmpty(encryptedText) || string.IsNullOrEmpty(ivString))
|
if(string.IsNullOrEmpty(secret) || string.IsNullOrEmpty(encryptedText) || string.IsNullOrEmpty(ivString))
|
||||||
return LSL_String.Empty;
|
return LSL_String.Empty;
|
||||||
|
|
||||||
string ret = Util.AESDecryptFrom(secret, encryptedText, ivString);
|
ReadOnlySpan<char> ret = Util.AESDecryptFrom(secret.AsSpan(), encryptedText.AsSpan(), ivString.AsSpan());
|
||||||
if(string.IsNullOrEmpty(ret))
|
if (ret.Length == 0)
|
||||||
{
|
{
|
||||||
OSSLShoutError("osAESDecryptFrom: Failed to decrypt!");
|
OSSLShoutError("osAESDecryptFrom: Failed to decrypt!");
|
||||||
return LSL_String.Empty;
|
return LSL_String.Empty;
|
||||||
}
|
}
|
||||||
return ret;
|
return ret.ToString();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -2256,6 +2256,11 @@ namespace OpenSim.Region.ScriptEngine.Shared
|
|||||||
m_string = s;
|
m_string = s;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public LSLString(ReadOnlySpan<char> s)
|
||||||
|
{
|
||||||
|
m_string = s.ToString();
|
||||||
|
}
|
||||||
|
|
||||||
public LSLString(double d)
|
public LSLString(double d)
|
||||||
{
|
{
|
||||||
string s = String.Format(Culture.FormatProvider, "{0:0.000000}", d);
|
string s = String.Format(Culture.FormatProvider, "{0:0.000000}", d);
|
||||||
@@ -2301,6 +2306,11 @@ namespace OpenSim.Region.ScriptEngine.Shared
|
|||||||
return new LSLString(s);
|
return new LSLString(s);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static public implicit operator LSLString(ReadOnlySpan<char> s)
|
||||||
|
{
|
||||||
|
return new LSLString(s);
|
||||||
|
}
|
||||||
|
|
||||||
public static string ToString(LSLString s)
|
public static string ToString(LSLString s)
|
||||||
{
|
{
|
||||||
return s.m_string;
|
return s.m_string;
|
||||||
@@ -2353,10 +2363,7 @@ namespace OpenSim.Region.ScriptEngine.Shared
|
|||||||
|
|
||||||
static public explicit operator LSLString(bool b)
|
static public explicit operator LSLString(bool b)
|
||||||
{
|
{
|
||||||
if (b)
|
return new LSLString( b ? "1" : "0");
|
||||||
return new LSLString("1");
|
|
||||||
else
|
|
||||||
return new LSLString("0");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static implicit operator Vector3(LSLString s)
|
public static implicit operator Vector3(LSLString s)
|
||||||
@@ -2379,6 +2386,11 @@ namespace OpenSim.Region.ScriptEngine.Shared
|
|||||||
return new list(new object[] { s });
|
return new list(new object[] { s });
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static implicit operator ReadOnlySpan<char>(LSLString s)
|
||||||
|
{
|
||||||
|
return s.m_string.AsSpan();
|
||||||
|
}
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region Overriders
|
#region Overriders
|
||||||
|
|||||||
Reference in New Issue
Block a user