private void HKDFTest(int Size, byte[] Salt, byte[] Key, byte[] Info, byte[] Output) { byte[] outBytes = new byte[Size]; using (HKDF gen = new HKDF(new SHA256())) { gen.Initialize(Salt, Key, Info); gen.Generate(outBytes, 0, Size); } if (Evaluate.AreEqual(outBytes, Output) == false) { throw new Exception("HKDF: Values are not equal! Expected: " + HexConverter.ToString(Output) + " Received: " + HexConverter.ToString(outBytes)); } using (HKDF gen = new HKDF(new HMAC(new SHA256()))) { gen.Initialize(Salt, Key, Info); gen.Generate(outBytes, 0, Size); } if (Evaluate.AreEqual(outBytes, Output) == false) { throw new Exception("HKDF: Values are not equal! Expected: " + HexConverter.ToString(Output) + " Received: " + HexConverter.ToString(outBytes)); } }
private void OnElementColorPropertyValueChanged(string oldvalue, string newvalue) { elementColorImage.color = HexConverter.HexToColor(newvalue); }
void Parse() { int entryCount = BitConverter.ToInt32(rawBytes, 8); int entryOffset = BitConverter.ToInt32(rawBytes, 12); for (int i = 0; i < entryCount; i++) { bevFile.Entries.Add(new Entry() { I_00 = BitConverter.ToInt32(rawBytes, entryOffset + 0), Index = BitConverter.ToInt32(rawBytes, entryOffset + 4).ToString(), I_08 = BitConverter.ToInt32(rawBytes, entryOffset + 8), I_12 = HexConverter.GetHexString(BitConverter.ToInt32(rawBytes, entryOffset + 12)), I_24 = BitConverter.ToInt32(rawBytes, entryOffset + 24) }); int count = BitConverter.ToInt32(rawBytes, entryOffset + 16); int offset = BitConverter.ToInt32(rawBytes, entryOffset + 20); //Idx int type0 = 0; int type1 = 0; int type2 = 0; int type3 = 0; int type4 = 0; int type5 = 0; int type6 = 0; if (count > 0) { for (int a = 0; a < count; a++) { short type = BitConverter.ToInt16(rawBytes, offset); short typeCount = BitConverter.ToInt16(rawBytes, offset + 2); int typeoffset = BitConverter.ToInt32(rawBytes, offset + 4); switch (type) { case 0: bevFile.Entries[i].Type0 = GetType0(typeCount, typeoffset, bevFile.Entries[i].Type0, type0); type0++; break; case 1: bevFile.Entries[i].Type1 = GetType1(typeCount, typeoffset, bevFile.Entries[i].Type1, type1); type1++; break; case 2: bevFile.Entries[i].Type2 = GetType2(typeCount, typeoffset, bevFile.Entries[i].Type2, type2); type2++; break; case 3: bevFile.Entries[i].Type3 = GetType3(typeCount, typeoffset, bevFile.Entries[i].Type3, type3); type3++; break; case 4: bevFile.Entries[i].Type4 = GetType4(typeCount, typeoffset, bevFile.Entries[i].Type4, type4); type4++; break; case 5: bevFile.Entries[i].Type5 = GetType5(typeCount, typeoffset, bevFile.Entries[i].Type5, type5); type5++; break; case 6: bevFile.Entries[i].Type6 = GetType6(typeCount, typeoffset, bevFile.Entries[i].Type6, type6); type6++; break; default: Console.WriteLine(String.Format("Encountered undefined BEV_Type = {0} (offset = {1}). Unable to continue.", type, offset)); Utils.WaitForInputThenQuit(); break; } offset += 8; } } entryOffset += 28; } }
public static string StringFromWkGuid(Guid wkGuid, string containerDN) { return(string.Format("<WKGUID={0},{1}>", HexConverter.ByteArrayToHexString(wkGuid.ToByteArray()), containerDN)); }
// Token: 0x06000E06 RID: 3590 RVA: 0x00041B15 File Offset: 0x0003FD15 public static string FormatAddressListDN(Guid guid) { return("/guid=" + HexConverter.ByteArrayToHexString(guid.ToByteArray())); }
private void MonteCarloTest(byte[] Key, byte[] Input, byte[] Output, bool Encrypt = true, int Count = 10000) { byte[] outBytes = new byte[Input.Length]; Array.Copy(Input, 0, outBytes, 0, outBytes.Length); using (THX engine = new THX()) { engine.Initialize(Encrypt, new KeyParams(Key)); for (int i = 0; i < Count; i++) { engine.Transform(outBytes, outBytes); } } if (Evaluate.AreEqual(outBytes, Output) == false) { throw new Exception("Twofish MonteCarlo: Arrays are not equal! Expected: " + HexConverter.ToString(Output) + " Received: " + HexConverter.ToString(outBytes)); } }
/// <summary> /// Official TwoFish key vectors /// </summary> /// /// <returns>State</returns> public string Run() { try { byte[] cip = new byte[16]; byte[] key = new byte[16]; // vector tests // // 128 bit keys string cipStr = VTDev.Projects.CEX.Test.Properties.Resources.twofishcipher_128; string keyStr = VTDev.Projects.CEX.Test.Properties.Resources.twofishkey_128; for (int i = 0; i < keyStr.Length; i += 32) { cip = HexConverter.Decode(cipStr.Substring(i, 32)); key = HexConverter.Decode(keyStr.Substring(i, 32)); // vector comparison VectorTest(key, _plainText, cip); } OnProgress(new TestEventArgs("Passed Twofish 128 bit key vector tests..")); // 192 bit keys cipStr = VTDev.Projects.CEX.Test.Properties.Resources.twofishcipher_192; keyStr = VTDev.Projects.CEX.Test.Properties.Resources.twofishkey_192; for (int i = 0, j = 0; j < keyStr.Length; i += 32, j += 48) { cip = HexConverter.Decode(cipStr.Substring(i, 32)); key = HexConverter.Decode(keyStr.Substring(j, 48)); // vector comparison VectorTest(key, _plainText, cip); } OnProgress(new TestEventArgs("Passed Twofish 192 bit key vector tests..")); // 256 bit keys cipStr = VTDev.Projects.CEX.Test.Properties.Resources.twofishcipher_256; keyStr = VTDev.Projects.CEX.Test.Properties.Resources.twofishkey_256; for (int i = 0, j = 0; j < keyStr.Length; i += 32, j += 64) { cip = HexConverter.Decode(cipStr.Substring(i, 32)); key = HexConverter.Decode(keyStr.Substring(j, 64)); // vector comparison VectorTest(key, _plainText, cip); } OnProgress(new TestEventArgs("Passed Twofish 256 bit key vector tests..")); // monte carlo tests: // // encrypt 10,000 rounds each key = new byte[16]; byte[] output = HexConverter.Decode("282BE7E4FA1FBDC29661286F1F310B7E"); // 128 key MonteCarloTest(key, _plainText, output); OnProgress(new TestEventArgs("Passed 10,000 round 128 bit key Monte Carlo encryption test..")); // 192 key key = new byte[24]; output = HexConverter.Decode("9AB71D7F280FF79F0D135BBD5FAB7E37"); MonteCarloTest(key, _plainText, output); OnProgress(new TestEventArgs("Passed 10,000 round 192 bit key Monte Carlo encryption test..")); // 256 key key = new byte[32]; output = HexConverter.Decode("04F2F36CA927AE506931DE8F78B2513C"); MonteCarloTest(key, _plainText, output); OnProgress(new TestEventArgs("Passed 10,000 round 256 bit key Monte Carlo encryption test..")); // decrypt 10,000 rounds key = new byte[16]; output = HexConverter.Decode("21D3F7F6724513946B72CFAE47DA2EED"); // 128 key MonteCarloTest(key, _plainText, output, false); OnProgress(new TestEventArgs("Passed 10,000 round 128 bit key Monte Carlo decryption test..")); // 192 key key = new byte[24]; output = HexConverter.Decode("B4582FA55072FCFEF538F39072F234A9"); MonteCarloTest(key, _plainText, output, false); OnProgress(new TestEventArgs("Passed 10,000 round 192 bit key Monte Carlo decryption test..")); // 256 key key = new byte[32]; output = HexConverter.Decode("BC7D078C4872063869DEAB891FB42761"); MonteCarloTest(key, _plainText, output, false); OnProgress(new TestEventArgs("Passed 10,000 round 256 bit key Monte Carlo decryption test..")); return(SUCCESS); } catch (Exception Ex) { string message = Ex.Message == null ? "" : Ex.Message; throw new Exception(FAILURE + message); } }
public static string EncryptJson(this IJObjectCrypto jObjectCrypto, string json, string publicKey) { var publicKeyBytes = HexConverter.HexToBinary(publicKey); return(jObjectCrypto.EncryptJson(json, publicKeyBytes)); }
public static string Encrypt(this IJObjectCrypto jObjectCrypto, Stream stream, string publicKey) { var publicKeyBytes = HexConverter.HexToBinary(publicKey); return(jObjectCrypto.Encrypt(stream, publicKeyBytes)); }
void EffectParser() { eepkFile.Effects = new List <Effect>(); List <ushort> effectIds = new List <ushort>(); //all lists are in sync with each other List <int> effectOffsets = new List <int>(); List <short> effectSize = new List <short>(); List <int> effectInfoOffsets = new List <int>(); for (int i = 0; i < totalEffects * 4; i += 4) { //Getting ID List data int current = BitConverter.ToInt32(rawBytes, i + pointerSectionLocation); if (current != 0) { effectIds.Add((Convert.ToUInt16(i / 4))); effectOffsets.Add(BitConverter.ToInt32(rawBytes, i + pointerSectionLocation)); } } for (int i = 0; i < effectIds.Count(); i++) { //Getting EffectInfo data, and making the representation instances effectSize.Add(BitConverter.ToInt16(rawBytes, effectOffsets[i] + 10)); effectInfoOffsets.Add(BitConverter.ToInt32(rawBytes, effectOffsets[i] + 12)); eepkFile.Effects.Add(new Effect()); eepkFile.Effects[i].EffectParts = new ObservableCollection <EffectPart>(); eepkFile.Effects[i].IndexNum = effectIds[i]; eepkFile.Effects[i].I_02 = BitConverter.ToUInt16(rawBytes, effectOffsets[i] + 2); int addedOffset = 0; for (int a = 0; a < effectSize[i]; a++) { //Fill in the Effect Info fields, adding a new entry per size BitArray composite_I_32 = new BitArray(new byte[1] { rawBytes[effectOffsets[i] + effectInfoOffsets[i] + addedOffset + 32] }); BitArray composite_I_39 = new BitArray(new byte[1] { rawBytes[effectOffsets[i] + effectInfoOffsets[i] + addedOffset + 39] }); BitArray composite_I_36 = new BitArray(new byte[1] { rawBytes[effectOffsets[i] + effectInfoOffsets[i] + addedOffset + 36] }); BitArray composite_I_37 = new BitArray(new byte[1] { rawBytes[effectOffsets[i] + effectInfoOffsets[i] + addedOffset + 37] }); eepkFile.Effects[i].EffectParts.Add(new EffectPart()); eepkFile.Effects[i].EffectParts[a].I_00 = BitConverter.ToUInt16(rawBytes, effectOffsets[i] + effectInfoOffsets[i] + addedOffset); eepkFile.Effects[i].EffectParts[a].I_02 = (AssetType)rawBytes[effectOffsets[i] + effectInfoOffsets[i] + addedOffset + 2]; eepkFile.Effects[i].EffectParts[a].I_03 = (EffectPart.Attachment)rawBytes[effectOffsets[i] + effectInfoOffsets[i] + addedOffset + 3]; eepkFile.Effects[i].EffectParts[a].I_04 = rawBytes[effectOffsets[i] + effectInfoOffsets[i] + addedOffset + 4]; eepkFile.Effects[i].EffectParts[a].I_05 = (EffectPart.DeactivationMode)rawBytes[effectOffsets[i] + effectInfoOffsets[i] + addedOffset + 5]; eepkFile.Effects[i].EffectParts[a].I_06 = rawBytes[effectOffsets[i] + effectInfoOffsets[i] + addedOffset + 6]; eepkFile.Effects[i].EffectParts[a].I_07 = rawBytes[effectOffsets[i] + effectInfoOffsets[i] + addedOffset + 7]; eepkFile.Effects[i].EffectParts[a].I_08 = BitConverter.ToInt32(rawBytes, effectOffsets[i] + effectInfoOffsets[i] + addedOffset + 8); eepkFile.Effects[i].EffectParts[a].I_12 = BitConverter.ToInt32(rawBytes, effectOffsets[i] + effectInfoOffsets[i] + addedOffset + 12); eepkFile.Effects[i].EffectParts[a].I_16 = BitConverter.ToInt32(rawBytes, effectOffsets[i] + effectInfoOffsets[i] + addedOffset + 16); eepkFile.Effects[i].EffectParts[a].I_20 = BitConverter.ToInt32(rawBytes, effectOffsets[i] + effectInfoOffsets[i] + addedOffset + 20); eepkFile.Effects[i].EffectParts[a].F_24 = BitConverter.ToSingle(rawBytes, effectOffsets[i] + effectInfoOffsets[i] + addedOffset + 24); eepkFile.Effects[i].EffectParts[a].I_28 = BitConverter.ToUInt16(rawBytes, effectOffsets[i] + effectInfoOffsets[i] + addedOffset + 28); eepkFile.Effects[i].EffectParts[a].I_30 = BitConverter.ToUInt16(rawBytes, effectOffsets[i] + effectInfoOffsets[i] + addedOffset + 30); eepkFile.Effects[i].EffectParts[a].I_32_0 = composite_I_32[0]; eepkFile.Effects[i].EffectParts[a].I_32_1 = composite_I_32[1]; eepkFile.Effects[i].EffectParts[a].I_32_2 = composite_I_32[2]; eepkFile.Effects[i].EffectParts[a].I_32_3 = composite_I_32[3]; eepkFile.Effects[i].EffectParts[a].I_32_4 = composite_I_32[4]; eepkFile.Effects[i].EffectParts[a].I_32_5 = composite_I_32[5]; eepkFile.Effects[i].EffectParts[a].I_32_6 = composite_I_32[6]; eepkFile.Effects[i].EffectParts[a].I_32_7 = composite_I_32[7]; eepkFile.Effects[i].EffectParts[a].I_34 = BitConverter.ToInt16(rawBytes, effectOffsets[i] + effectInfoOffsets[i] + addedOffset + 34); eepkFile.Effects[i].EffectParts[a].I_36_0 = composite_I_36[0]; eepkFile.Effects[i].EffectParts[a].I_36_1 = composite_I_36[1]; eepkFile.Effects[i].EffectParts[a].I_36_2 = composite_I_36[2]; eepkFile.Effects[i].EffectParts[a].I_36_3 = composite_I_36[3]; eepkFile.Effects[i].EffectParts[a].I_36_4 = composite_I_36[4]; eepkFile.Effects[i].EffectParts[a].I_36_5 = composite_I_36[5]; eepkFile.Effects[i].EffectParts[a].I_36_6 = composite_I_36[6]; eepkFile.Effects[i].EffectParts[a].I_36_7 = composite_I_36[7]; eepkFile.Effects[i].EffectParts[a].I_37_0 = composite_I_37[0]; eepkFile.Effects[i].EffectParts[a].I_37_1 = composite_I_37[1]; eepkFile.Effects[i].EffectParts[a].I_37_2 = composite_I_37[2]; eepkFile.Effects[i].EffectParts[a].I_37_3 = composite_I_37[3]; eepkFile.Effects[i].EffectParts[a].I_37_4 = composite_I_37[4]; eepkFile.Effects[i].EffectParts[a].I_37_5 = composite_I_37[5]; eepkFile.Effects[i].EffectParts[a].I_37_6 = composite_I_37[6]; eepkFile.Effects[i].EffectParts[a].I_37_7 = composite_I_37[7]; eepkFile.Effects[i].EffectParts[a].I_38_a = HexConverter.GetHexString(Int4Converter.ToInt4(rawBytes[effectOffsets[i] + effectInfoOffsets[i] + addedOffset + 38])[0]); eepkFile.Effects[i].EffectParts[a].I_38_b = HexConverter.GetHexString(Int4Converter.ToInt4(rawBytes[effectOffsets[i] + effectInfoOffsets[i] + addedOffset + 38])[1]); eepkFile.Effects[i].EffectParts[a].I_39_0 = composite_I_39[0]; eepkFile.Effects[i].EffectParts[a].I_39_1 = composite_I_39[1]; eepkFile.Effects[i].EffectParts[a].I_39_2 = composite_I_39[2]; eepkFile.Effects[i].EffectParts[a].I_39_3 = composite_I_39[3]; eepkFile.Effects[i].EffectParts[a].I_39_4 = composite_I_39[4]; eepkFile.Effects[i].EffectParts[a].I_39_5 = composite_I_39[5]; eepkFile.Effects[i].EffectParts[a].I_39_6 = composite_I_39[6]; eepkFile.Effects[i].EffectParts[a].I_39_7 = composite_I_39[7]; eepkFile.Effects[i].EffectParts[a].POSITION_X = BitConverter.ToSingle(rawBytes, effectOffsets[i] + effectInfoOffsets[i] + addedOffset + 40); eepkFile.Effects[i].EffectParts[a].POSITION_Y = BitConverter.ToSingle(rawBytes, effectOffsets[i] + effectInfoOffsets[i] + addedOffset + 44); eepkFile.Effects[i].EffectParts[a].POSITION_Z = BitConverter.ToSingle(rawBytes, effectOffsets[i] + effectInfoOffsets[i] + addedOffset + 48); eepkFile.Effects[i].EffectParts[a].F_52 = (float)Utils.ConvertRadiansToDegrees(BitConverter.ToSingle(rawBytes, effectOffsets[i] + effectInfoOffsets[i] + addedOffset + 52)); eepkFile.Effects[i].EffectParts[a].F_56 = (float)Utils.ConvertRadiansToDegrees(BitConverter.ToSingle(rawBytes, effectOffsets[i] + effectInfoOffsets[i] + addedOffset + 56)); eepkFile.Effects[i].EffectParts[a].F_60 = (float)Utils.ConvertRadiansToDegrees(BitConverter.ToSingle(rawBytes, effectOffsets[i] + effectInfoOffsets[i] + addedOffset + 60)); eepkFile.Effects[i].EffectParts[a].F_64 = (float)Utils.ConvertRadiansToDegrees(BitConverter.ToSingle(rawBytes, effectOffsets[i] + effectInfoOffsets[i] + addedOffset + 64)); eepkFile.Effects[i].EffectParts[a].F_68 = (float)Utils.ConvertRadiansToDegrees(BitConverter.ToSingle(rawBytes, effectOffsets[i] + effectInfoOffsets[i] + addedOffset + 68)); eepkFile.Effects[i].EffectParts[a].F_72 = (float)Utils.ConvertRadiansToDegrees(BitConverter.ToSingle(rawBytes, effectOffsets[i] + effectInfoOffsets[i] + addedOffset + 72)); eepkFile.Effects[i].EffectParts[a].SIZE_1 = BitConverter.ToSingle(rawBytes, effectOffsets[i] + effectInfoOffsets[i] + addedOffset + 76); eepkFile.Effects[i].EffectParts[a].SIZE_2 = BitConverter.ToSingle(rawBytes, effectOffsets[i] + effectInfoOffsets[i] + addedOffset + 80); eepkFile.Effects[i].EffectParts[a].F_84 = BitConverter.ToSingle(rawBytes, effectOffsets[i] + effectInfoOffsets[i] + addedOffset + 84); eepkFile.Effects[i].EffectParts[a].F_88 = BitConverter.ToSingle(rawBytes, effectOffsets[i] + effectInfoOffsets[i] + addedOffset + 88); eepkFile.Effects[i].EffectParts[a].I_92 = BitConverter.ToUInt16(rawBytes, effectOffsets[i] + effectInfoOffsets[i] + addedOffset + 92); eepkFile.Effects[i].EffectParts[a].I_94 = BitConverter.ToUInt16(rawBytes, effectOffsets[i] + effectInfoOffsets[i] + addedOffset + 94); int eskOffset = BitConverter.ToInt32(rawBytes, effectOffsets[i] + effectInfoOffsets[i] + addedOffset + 96); if (eskOffset != 0) { //Get ESK string if it exists, otherwise put it as "NULL" try { eepkFile.Effects[i].EffectParts[a].ESK = Utils.GetString(bytes, effectOffsets[i] + effectInfoOffsets[i] + addedOffset + eskOffset); } catch { throw new ArgumentOutOfRangeException("Unable to get string!"); } } else { eepkFile.Effects[i].EffectParts[a].ESK = "NULL"; } addedOffset += 100; } } }
private static unsafe void UnsafeEncode(byte b, char *pch) { pch[0] = HexConverter.ToCharLower(b >> 4); pch[1] = HexConverter.ToCharLower(b); }
void AssetParser() { eepkFile.Assets = new List <AssetContainer>(); int addedOffset = 0; List <short> assetEntrySize = new List <short>(); List <int> assetEntryStartOffset = new List <int>(); for (int i = 0; i < totalAssetContainerEntries; i++) { eepkFile.Assets.Add(new AssetContainer()); eepkFile.Assets[i].I_00 = HexConverter.GetHexString(BitConverter.ToInt32(rawBytes, assetSectionLocation + addedOffset)); eepkFile.Assets[i].I_04 = HexConverter.GetHexString(rawBytes[assetSectionLocation + addedOffset + 4]); eepkFile.Assets[i].I_05 = HexConverter.GetHexString(rawBytes[assetSectionLocation + addedOffset + 5]); eepkFile.Assets[i].I_06 = HexConverter.GetHexString(rawBytes[assetSectionLocation + addedOffset + 6]); eepkFile.Assets[i].I_07 = HexConverter.GetHexString(rawBytes[assetSectionLocation + addedOffset + 7]); eepkFile.Assets[i].I_08 = HexConverter.GetHexString(BitConverter.ToInt32(rawBytes, assetSectionLocation + addedOffset + 8)); eepkFile.Assets[i].I_12 = HexConverter.GetHexString(BitConverter.ToInt32(rawBytes, assetSectionLocation + addedOffset + 12)); eepkFile.Assets[i].I_16 = (AssetType)BitConverter.ToUInt16(rawBytes, assetSectionLocation + addedOffset + 16); eepkFile.Assets[i].FILES = new string[3]; int count = 0; for (int e = 0; e < 3 * 4; e += 4) { //Getting the file string if it exists, and assigning it to the correct field int fileOffset = BitConverter.ToInt32(rawBytes, assetSectionLocation + addedOffset + 36 + e); if (fileOffset != 0) { eepkFile.Assets[i].FILES[count] = Utils.GetString(bytes, fileOffset + assetSectionLocation + addedOffset); } else if (fileOffset == 0) { //If no string, then set it to null eepkFile.Assets[i].FILES[count] = "NULL"; } count++; } assetEntrySize.Add(BitConverter.ToInt16(rawBytes, assetSectionLocation + addedOffset + 30)); assetEntryStartOffset.Add(BitConverter.ToInt32(rawBytes, assetSectionLocation + addedOffset + 32) + assetSectionLocation + addedOffset); addedOffset += 48; } for (int i = 0; i < assetEntrySize.Count(); i++) { //iterate over the Asset Containers addedOffset = 0; int index = 0; eepkFile.Assets[i].AssetEntries = new List <Asset_Entry>(); for (int f = 0; f < assetEntrySize[i]; f++) { //iterate over Asset Entries of the current Asset Container int totalStrings = rawBytes[assetEntryStartOffset[i] + addedOffset + 3]; eepkFile.Assets[i].AssetEntries.Add(new Asset_Entry()); eepkFile.Assets[i].AssetEntries[f].ReadOnly_Index = index; index++; eepkFile.Assets[i].AssetEntries[f].I_00 = BitConverter.ToInt16(rawBytes, assetEntryStartOffset[i] + addedOffset); int offsetForStringInital = BitConverter.ToInt32(rawBytes, assetEntryStartOffset[i] + addedOffset + 8) + assetEntryStartOffset[i] + addedOffset; eepkFile.Assets[i].AssetEntries[f].FILES = new Asset_File[totalStrings].ToList(); eepkFile.Assets[i].AssetEntries[f].UNK_NUMBERS = new String[5] { "NULL", "NULL", "NULL", "NULL", "NULL" }; if (BitConverter.ToInt32(rawBytes, assetEntryStartOffset[i] + addedOffset + 8) != 0)//Safety check { List <int> offsetsForFileString = new List <int>(); for (int z = 0; z < totalStrings * 4; z += 4) { //offsetsForFileString.Add(BitConverter.ToInt32(rawBytes, BitConverter.ToInt32(rawBytes, assetEntryStartOffset[i] + addedOffset + 8) + assetEntryStartOffset[i] + addedOffset) + assetEntryStartOffset[i] + addedOffset + z); if (BitConverter.ToInt32(rawBytes, offsetForStringInital + z) != 0) { offsetsForFileString.Add(BitConverter.ToInt32(rawBytes, offsetForStringInital + z) + +assetEntryStartOffset[i] + addedOffset); } else { //No file string in this space offsetsForFileString.Add(0); } if (offsetsForFileString[z / 4] != 0) { eepkFile.Assets[i].AssetEntries[f].FILES[z / 4] = new Asset_File() { Path = Utils.GetString(bytes, offsetsForFileString[z / 4]) }; } else { eepkFile.Assets[i].AssetEntries[f].FILES[z / 4] = new Asset_File() { Path = "NULL" }; } } } addedOffset += 12; } } }
public void HexConverter_ConvertBack() { IValueConverter converter; object actualValue; Type expectedType; converter = new HexConverter(); expectedType = typeof(int); // // Test with null. // try { converter.ConvertBack(null); Assert.Fail("Expected ArgumentNullException to be thrown."); } catch (ArgumentNullException) { } // // Test with incorrect value. // try { converter.ConvertBack("true"); Assert.Fail("Expected FormatException to be thrown."); } catch (FormatException) { } try { converter.ConvertBack("FFFFFFFFFFFFF"); Assert.Fail("Expected OverflowException to be thrown."); } catch (OverflowException) { } // // Test with 0. // actualValue = converter.ConvertBack("0"); Assert.IsNotNull(actualValue, "Converted value is null."); Assert.AreEqual(expectedType, actualValue.GetType(), "Type of converted value is incorrect."); Assert.AreEqual(0, actualValue, "Converted value is incorrect."); // // Test with lower case value. // actualValue = converter.ConvertBack("abc"); Assert.IsNotNull(actualValue, "Converted value is null."); Assert.AreEqual(expectedType, actualValue.GetType(), "Type of converted value is incorrect."); Assert.AreEqual(0xABC, actualValue, "Converted value is incorrect."); // // Test with upper case value. // actualValue = converter.ConvertBack("F00D"); Assert.IsNotNull(actualValue, "Converted value is null."); Assert.AreEqual(expectedType, actualValue.GetType(), "Type of converted value is incorrect."); Assert.AreEqual(0xF00D, actualValue, "Converted value is incorrect."); }
public void HexConverter_Convert() { IValueConverter converter; object actualValue; Type expectedType; converter = new HexConverter(); expectedType = typeof(string); // // Test with null. // try { converter.Convert(null); Assert.Fail("Expected ArgumentNullException to be thrown."); } catch (ArgumentNullException) { } // // Test with incorrect type. // try { converter.Convert("true"); Assert.Fail("Expected ArgumentException to be thrown."); } catch (ArgumentException) { } // // Test with 0. // actualValue = converter.Convert(0); Assert.IsNotNull(actualValue, "Converted value is null."); Assert.AreEqual(expectedType, actualValue.GetType(), "Type of converted value is incorrect."); Assert.AreEqual("0000", actualValue, "Converted value is incorrect."); // // Test with negative value. // actualValue = converter.Convert(-1); Assert.IsNotNull(actualValue, "Converted value is null."); Assert.AreEqual(expectedType, actualValue.GetType(), "Type of converted value is incorrect."); Assert.AreEqual("FFFFFFFF", actualValue, "Converted value is incorrect."); // // Test with positive value. // actualValue = converter.Convert(1024); Assert.IsNotNull(actualValue, "Converted value is null."); Assert.AreEqual(expectedType, actualValue.GetType(), "Type of converted value is incorrect."); Assert.AreEqual("0400", actualValue, "Converted value is incorrect."); }
internal void SaveIntoMessageProperties(MessageItem messageItem, bool isClear) { SharingProvider primarySharingProvider = this.context.PrimarySharingProvider; messageItem.SetOrDeleteProperty(InternalSchema.ProviderGuidBinary, isClear ? null : primarySharingProvider.Guid.ToByteArray()); messageItem.SetOrDeleteProperty(InternalSchema.SharingProviderName, isClear ? null : primarySharingProvider.Name); messageItem.SetOrDeleteProperty(InternalSchema.SharingProviderUrl, isClear ? null : primarySharingProvider.Url); messageItem.SetOrDeleteProperty(InternalSchema.SharingCapabilities, isClear ? null : this.context.SharingCapabilities); messageItem.SetOrDeleteProperty(InternalSchema.SharingFlavor, isClear ? null : this.context.SharingFlavor); messageItem.SetOrDeleteProperty(InternalSchema.SharingRemoteType, isClear ? null : this.context.FolderClass); messageItem.SetOrDeleteProperty(InternalSchema.SharingLocalType, isClear ? null : this.context.FolderClass); messageItem.SetOrDeleteProperty(InternalSchema.SharingRemoteName, isClear ? null : this.context.FolderName); messageItem.SetOrDeleteProperty(InternalSchema.SharingLocalName, isClear ? null : this.context.FolderName); messageItem.SetOrDeleteProperty(InternalSchema.SharingRemoteUid, isClear ? null : this.context.FolderId.ToHexEntryId()); messageItem.SetOrDeleteProperty(InternalSchema.SharingLocalUid, isClear ? null : this.context.FolderId.ToHexEntryId()); messageItem.SetOrDeleteProperty(InternalSchema.SharingRemoteStoreUid, isClear ? null : HexConverter.ByteArrayToHexString(this.context.MailboxId)); messageItem.SetOrDeleteProperty(InternalSchema.SharingLocalStoreUid, isClear ? null : HexConverter.ByteArrayToHexString(this.context.MailboxId)); messageItem.SetOrDeleteProperty(InternalSchema.SharingInitiatorName, isClear ? null : this.context.InitiatorName); messageItem.SetOrDeleteProperty(InternalSchema.SharingInitiatorSmtp, isClear ? null : this.context.InitiatorSmtpAddress); messageItem.SetOrDeleteProperty(InternalSchema.SharingInitiatorEntryId, isClear ? null : this.context.InitiatorEntryId); messageItem.SetOrDeleteProperty(InternalSchema.SharingPermissions, isClear ? null : this.context.SharingPermissions); messageItem.SetOrDeleteProperty(InternalSchema.SharingDetail, isClear ? null : this.context.SharingDetail); }
public static void Encrypt(this IJObjectCrypto jObjectCrypto, JObject jObject, string publicKey) { var publicKeyBytes = HexConverter.HexToBinary(publicKey); jObjectCrypto.Encrypt(jObject, publicKeyBytes); }
public void OddNumberDigitException() { HexConverter converter = new HexConverter(); converter.ToBytes("123"); }
public static string DecryptJson(this IJObjectCrypto jObjectCrypto, string json, string privateKey) { var privateKeyBytes = HexConverter.HexToBinary(privateKey); return(jObjectCrypto.DecryptJson(json, privateKeyBytes)); }
private void VectorTest(byte[] Key, byte[] Input, byte[] Output) { byte[] outBytes = new byte[Input.Length]; using (THX tfx = new THX()) { tfx.Initialize(true, new KeyParams(Key)); tfx.EncryptBlock(Input, outBytes); } if (Evaluate.AreEqual(outBytes, Output) == false) { throw new Exception("Twofish Vector: Encrypted arrays are not equal! Expected: " + HexConverter.ToString(Output) + " Received: " + HexConverter.ToString(outBytes)); } using (THX tfx = new THX()) { tfx.Initialize(false, new KeyParams(Key)); tfx.Transform(Output, outBytes); } if (Evaluate.AreEqual(outBytes, Input) == false) { throw new Exception("Twofish Vector: Decrypted arrays are not equal! Expected: " + HexConverter.ToString(Input) + " Received: " + HexConverter.ToString(outBytes)); } }
public static string Decrypt(this IJObjectCrypto jObjectCrypto, Stream stream, string privateKey) { var privateKeyBytes = HexConverter.HexToBinary(privateKey); return(jObjectCrypto.Decrypt(stream, privateKeyBytes)); }
internal static X509Certificate2Collection BuildBagOfCerts(KeyInfoX509Data keyInfoX509Data, CertUsageType certUsageType) { X509Certificate2Collection collection = new X509Certificate2Collection(); ArrayList decryptionIssuerSerials = (certUsageType == CertUsageType.Decryption ? new ArrayList() : null); if (keyInfoX509Data.Certificates != null) { foreach (X509Certificate2 certificate in keyInfoX509Data.Certificates) { switch (certUsageType) { case CertUsageType.Verification: collection.Add(certificate); break; } } } if (keyInfoX509Data.SubjectNames == null && keyInfoX509Data.IssuerSerials == null && keyInfoX509Data.SubjectKeyIds == null && decryptionIssuerSerials == null) { return(collection); } // Open LocalMachine and CurrentUser "Other People"/"My" stores. X509Store[] stores = new X509Store[2]; string storeName = (certUsageType == CertUsageType.Verification ? "AddressBook" : "My"); stores[0] = new X509Store(storeName, StoreLocation.CurrentUser); stores[1] = new X509Store(storeName, StoreLocation.LocalMachine); for (int index = 0; index < stores.Length; index++) { if (stores[index] != null) { X509Certificate2Collection filters = null; // We don't care if we can't open the store. try { stores[index].Open(OpenFlags.ReadOnly | OpenFlags.OpenExistingOnly); filters = stores[index].Certificates; stores[index].Close(); if (keyInfoX509Data.SubjectNames != null) { foreach (string subjectName in keyInfoX509Data.SubjectNames) { filters = filters.Find(X509FindType.FindBySubjectDistinguishedName, subjectName, false); } } if (keyInfoX509Data.IssuerSerials != null) { foreach (X509IssuerSerial issuerSerial in keyInfoX509Data.IssuerSerials) { filters = filters.Find(X509FindType.FindByIssuerDistinguishedName, issuerSerial.IssuerName, false); filters = filters.Find(X509FindType.FindBySerialNumber, issuerSerial.SerialNumber, false); } } if (keyInfoX509Data.SubjectKeyIds != null) { foreach (byte[] ski in keyInfoX509Data.SubjectKeyIds) { string hex = HexConverter.ToString(ski); filters = filters.Find(X509FindType.FindBySubjectKeyIdentifier, hex, false); } } if (decryptionIssuerSerials != null) { foreach (X509IssuerSerial issuerSerial in decryptionIssuerSerials) { filters = filters.Find(X509FindType.FindByIssuerDistinguishedName, issuerSerial.IssuerName, false); filters = filters.Find(X509FindType.FindBySerialNumber, issuerSerial.SerialNumber, false); } } } // Store doesn't exist, no read permissions, other system error catch (CryptographicException) { } // Opening LocalMachine stores (other than Root or CertificateAuthority) on Linux catch (PlatformNotSupportedException) { } if (filters != null) { collection.AddRange(filters); } } } return(collection); }
public static void Decrypt(this IJObjectCrypto jObjectCrypto, JObject jObject, string privateKey) { var privateKeyBytes = HexConverter.HexToBinary(privateKey); jObjectCrypto.Decrypt(jObject, privateKeyBytes); }
private void UpdateSchedule(ref XDocument msg) { for (int i = 0; i <= 6; i++) // for each day of week { var value = msg.Descendants("Device.System.Power.Schedule." + i + ".List").First().Value; if (value.Length > 0) { string[] encodedHours = value.Split('-'); var scheduleList = new List <Schedule>(); foreach (var h in encodedHours) { if (!String.IsNullOrEmpty(h)) { scheduleList.Add(DecodeHelper.DecodeString(i, h)); } } msg.Descendants("Device.System.Power.Schedule." + i).First().Value = HexConverter.PreparePowerSchedule(scheduleList); } } }
private unsafe void WriteUriAttributeText(char *pSrc, char *pSrcEnd) { if (_endsWithAmpersand) { if (pSrcEnd - pSrc > 0 && pSrc[0] != '{') { OutputRestAmps(); } _endsWithAmpersand = false; } fixed(char *pDstBegin = _bufChars) { char *pDst = pDstBegin + _bufPos; char ch = (char)0; while (true) { char *pDstEnd = pDst + (pSrcEnd - pSrc); if (pDstEnd > pDstBegin + _bufLen) { pDstEnd = pDstBegin + _bufLen; } while (pDst < pDstEnd && (_xmlCharType.IsAttributeValueChar((char)(ch = *pSrc)) && ch < 0x80)) { *pDst++ = (char)ch; pSrc++; } Debug.Assert(pSrc <= pSrcEnd); // end of value if (pSrc >= pSrcEnd) { break; } // end of buffer if (pDst >= pDstEnd) { _bufPos = (int)(pDst - pDstBegin); FlushBuffer(); pDst = pDstBegin + 1; continue; } // some character needs to be escaped switch (ch) { case '&': if (pSrc + 1 == pSrcEnd) { _endsWithAmpersand = true; } else if (pSrc[1] != '{') { pDst = AmpEntity(pDst); break; } *pDst++ = (char)ch; break; case '"': pDst = QuoteEntity(pDst); break; case '<': case '>': case '\'': case (char)0x9: *pDst++ = (char)ch; break; case (char)0xD: // do not normalize new lines in attributes - just escape them pDst = CarriageReturnEntity(pDst); break; case (char)0xA: // do not normalize new lines in attributes - just escape them pDst = LineFeedEntity(pDst); break; default: Debug.Assert(_uriEscapingBuffer?.Length > 0); fixed(byte *pUriEscapingBuffer = _uriEscapingBuffer) { byte *pByte = pUriEscapingBuffer; byte *pEnd = pByte; XmlUtf8RawTextWriter.CharToUTF8(ref pSrc, pSrcEnd, ref pEnd); while (pByte < pEnd) { *pDst++ = (char)'%'; *pDst++ = (char)HexConverter.ToCharUpper(*pByte >> 4); *pDst++ = (char)HexConverter.ToCharUpper(*pByte); pByte++; } } continue; } pSrc++; } _bufPos = (int)(pDst - pDstBegin); } }
// Token: 0x06000E08 RID: 3592 RVA: 0x00041B3A File Offset: 0x0003FD3A public static string FormatLegacyDnFromGuid(Guid namingContext, Guid guid) { return("/o=NT5/ou=" + HexConverter.ByteArrayToHexString(namingContext.ToByteArray()) + "/cn=" + HexConverter.ByteArrayToHexString(guid.ToByteArray())); }
/// <summary> /// Formats a Guid as a UTF8 string. /// </summary> /// <param name="value">Value to format</param> /// <param name="destination">Buffer to write the UTF8-formatted value to</param> /// <param name="bytesWritten">Receives the length of the formatted text in bytes</param> /// <param name="format">The standard format to use</param> /// <returns> /// true for success. "bytesWritten" contains the length of the formatted text in bytes. /// false if buffer was too short. Iteratively increase the size of the buffer and retry until it succeeds. /// </returns> /// <remarks> /// Formats supported: /// D (default) nnnnnnnn-nnnn-nnnn-nnnn-nnnnnnnnnnnn /// B {nnnnnnnn-nnnn-nnnn-nnnn-nnnnnnnnnnnn} /// P (nnnnnnnn-nnnn-nnnn-nnnn-nnnnnnnnnnnn) /// N nnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnn /// </remarks> /// <exceptions> /// <cref>System.FormatException</cref> if the format is not valid for this data type. /// </exceptions> public static bool TryFormat(Guid value, Span <byte> destination, out int bytesWritten, StandardFormat format = default) { const int INSERT_DASHES = unchecked ((int)0x80000000); const int NO_DASHES = 0; const int INSERT_CURLY_BRACES = (CloseBrace << 16) | (OpenBrace << 8); const int INSERT_ROUND_BRACES = (CloseParen << 16) | (OpenParen << 8); const int NO_BRACES = 0; const int LEN_GUID_BASE = 32; const int LEN_ADD_DASHES = 4; const int LEN_ADD_BRACES = 2; // This is a 32-bit value whose contents (where 0 is the low byte) are: // 0th byte: minimum required length of the output buffer, // 1st byte: the ASCII byte to insert for the opening brace position (or 0 if no braces), // 2nd byte: the ASCII byte to insert for the closing brace position (or 0 if no braces), // 3rd byte: high bit set if dashes are to be inserted. // // The reason for keeping a single flag instead of separate vars is that we can avoid register spillage // as we build up the output value. int flags; switch (FormattingHelpers.GetSymbolOrDefault(format, 'D')) { case 'D': // nnnnnnnn-nnnn-nnnn-nnnn-nnnnnnnnnnnn flags = INSERT_DASHES + NO_BRACES + LEN_GUID_BASE + LEN_ADD_DASHES; break; case 'B': // {nnnnnnnn-nnnn-nnnn-nnnn-nnnnnnnnnnnn} flags = INSERT_DASHES + INSERT_CURLY_BRACES + LEN_GUID_BASE + LEN_ADD_DASHES + LEN_ADD_BRACES; break; case 'P': // (nnnnnnnn-nnnn-nnnn-nnnn-nnnnnnnnnnnn) flags = INSERT_DASHES + INSERT_ROUND_BRACES + LEN_GUID_BASE + LEN_ADD_DASHES + LEN_ADD_BRACES; break; case 'N': // nnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnn flags = NO_BRACES + NO_DASHES + LEN_GUID_BASE; break; default: return(FormattingHelpers.TryFormatThrowFormatException(out bytesWritten)); } // At this point, the low byte of flags contains the minimum required length if ((byte)flags > destination.Length) { bytesWritten = 0; return(false); } bytesWritten = (byte)flags; flags >>= 8; // At this point, the low byte of flags contains the opening brace char (if any) if ((byte)flags != 0) { destination[0] = (byte)flags; destination = destination.Slice(1); } flags >>= 8; // At this point, the low byte of flags contains the closing brace char (if any) // And since we're performing arithmetic shifting the high bit of flags is set (flags is negative) if dashes are required DecomposedGuid guidAsBytes = default; guidAsBytes.Guid = value; // When a GUID is blitted, the first three components are little-endian, and the last component is big-endian. // The line below forces the JIT to hoist the bounds check for the following segment. // The JIT will optimize away the read, but it cannot optimize away the bounds check // because it may have an observable side effect (throwing). // We use 8 instead of 7 so that we also capture the dash if we're asked to insert one. { _ = destination[8]; } HexConverter.ToBytesBuffer(guidAsBytes.Byte03, destination, 0, HexConverter.Casing.Lower); HexConverter.ToBytesBuffer(guidAsBytes.Byte02, destination, 2, HexConverter.Casing.Lower); HexConverter.ToBytesBuffer(guidAsBytes.Byte01, destination, 4, HexConverter.Casing.Lower); HexConverter.ToBytesBuffer(guidAsBytes.Byte00, destination, 6, HexConverter.Casing.Lower); if (flags < 0 /* use dash? */) { destination[8] = Dash; destination = destination.Slice(9); } else { destination = destination.Slice(8); } { _ = destination[4]; } HexConverter.ToBytesBuffer(guidAsBytes.Byte05, destination, 0, HexConverter.Casing.Lower); HexConverter.ToBytesBuffer(guidAsBytes.Byte04, destination, 2, HexConverter.Casing.Lower); if (flags < 0 /* use dash? */) { destination[4] = Dash; destination = destination.Slice(5); } else { destination = destination.Slice(4); } { _ = destination[4]; } HexConverter.ToBytesBuffer(guidAsBytes.Byte07, destination, 0, HexConverter.Casing.Lower); HexConverter.ToBytesBuffer(guidAsBytes.Byte06, destination, 2, HexConverter.Casing.Lower); if (flags < 0 /* use dash? */) { destination[4] = Dash; destination = destination.Slice(5); } else { destination = destination.Slice(4); } { _ = destination[4]; } HexConverter.ToBytesBuffer(guidAsBytes.Byte08, destination, 0, HexConverter.Casing.Lower); HexConverter.ToBytesBuffer(guidAsBytes.Byte09, destination, 2, HexConverter.Casing.Lower); if (flags < 0 /* use dash? */) { destination[4] = Dash; destination = destination.Slice(5); } else { destination = destination.Slice(4); } { _ = destination[11]; } // can't hoist bounds check on the final brace (if exists) HexConverter.ToBytesBuffer(guidAsBytes.Byte10, destination, 0, HexConverter.Casing.Lower); HexConverter.ToBytesBuffer(guidAsBytes.Byte11, destination, 2, HexConverter.Casing.Lower); HexConverter.ToBytesBuffer(guidAsBytes.Byte12, destination, 4, HexConverter.Casing.Lower); HexConverter.ToBytesBuffer(guidAsBytes.Byte13, destination, 6, HexConverter.Casing.Lower); HexConverter.ToBytesBuffer(guidAsBytes.Byte14, destination, 8, HexConverter.Casing.Lower); HexConverter.ToBytesBuffer(guidAsBytes.Byte15, destination, 10, HexConverter.Casing.Lower); if ((byte)flags != 0) { destination[12] = (byte)flags; } return(true); }
private void KDF2Test(int Size, byte[] Salt, byte[] Output) { byte[] outBytes = new byte[Size]; using (KDF2 gen = new KDF2(new SHA256())) { gen.Initialize(Salt); gen.Generate(outBytes, 0, Size); } if (Evaluate.AreEqual(outBytes, Output) == false) { throw new Exception("KDF2Drbg: Values are not equal! Expected: " + HexConverter.ToString(Output) + " Received: " + HexConverter.ToString(outBytes)); } }
private void buttonConnect_Click(object sender, RoutedEventArgs e) { var destination = HexConverter.ToBytes(textBoxDestination.Text); if (destination != null) { double ammountDouble; if (double.TryParse(textBoxAmmount.Text, out ammountDouble)) { double feeDouble; if (double.TryParse(textBoxFee.Text, out feeDouble)) { var balance = ConnectionJob.GetSmallUnitsBalance(httpProvider, SenderWallet.PublicKey); if (balance != null) { var ammount = GetSmallestUnits(ammountDouble); var fee = GetSmallestUnits(feeDouble); if (_nonce == null) { _nonce = httpProvider.PeerPost <string, uint>(HexConverter.ToPrefixString(SenderWallet.PublicKey), @"http://127.0.0.1:8125/transaction/count").Result; } else { _nonce = _nonce + 1; } if ((balance + fee - 1) > ammount) { var tx = new Transaction() { Ammount = ammount, Destination = ByteManipulator.TruncateMostSignificatZeroBytes(destination), Fee = fee, Network = new byte[] { 1 }, Nonce = _nonce.Value, Source = ByteManipulator.TruncateMostSignificatZeroBytes(SenderWallet.PublicKey) }; tx.Sign(SenderWallet.PrivateKey); var response = httpProvider.PeerPost <string, string>(HexConverter.ToPrefixString(tx.Serialize()), @"http://127.0.0.1:8125/transaction/relay").Result; if (response != "ok") { MessageBox.Show("Sending transaction failed", "Error", MessageBoxButton.OK, MessageBoxImage.Error); } } else //insufficient balance { MessageBox.Show("Insufficient balance", "Error", MessageBoxButton.OK, MessageBoxImage.Information); } } else //could not fetch balance { MessageBox.Show("Could not fetch nonce", "Error", MessageBoxButton.OK, MessageBoxImage.Error); } } else //invalid fee { MessageBox.Show("Invalid fee", "Error", MessageBoxButton.OK, MessageBoxImage.Error); } } else //invalid ammount { MessageBox.Show("Invalid invalid ammount", "Error", MessageBoxButton.OK, MessageBoxImage.Error); } } else //invalid destination { MessageBox.Show("Invalid invalid destination", "Error", MessageBoxButton.OK, MessageBoxImage.Error); } }
public string GetHexString(bool hexPrefix = true) => HexConverter.GetHex <Address>(this, hexPrefix: hexPrefix);
public override void Initialize(IRgb color) { HexConverter.ToColorSpace(color, this); }
internal void ReadFromMessageItem(MessageItem messageItem, bool isDraft) { byte[] array = messageItem.GetValueOrDefault <byte[]>(InternalSchema.ProviderGuidBinary, null); if (array == null) { ExTraceGlobals.SharingTracer.TraceDebug <string>((long)this.GetHashCode(), "{0}: ProviderGuidBinary is missing, reading from XSharingProviderGuid", messageItem.Session.UserLegacyDN); string valueOrDefault = messageItem.GetValueOrDefault <string>(InternalSchema.XSharingProviderGuid, null); if (valueOrDefault == null) { ExTraceGlobals.SharingTracer.TraceError <string>((long)this.GetHashCode(), "{0}: XSharingProviderGuid is missing", messageItem.Session.UserLegacyDN); throw new NotSupportedSharingMessageException(); } try { array = HexConverter.HexStringToByteArray(valueOrDefault); } catch (FormatException) { ExTraceGlobals.SharingTracer.TraceError <string>((long)this.GetHashCode(), "{0}: XSharingProviderGuid is invalid", messageItem.Session.UserLegacyDN); throw new NotSupportedSharingMessageException(); } } SharingProvider sharingProvider = SharingProvider.FromGuid(new Guid(array)); if (sharingProvider == null) { ExTraceGlobals.SharingTracer.TraceError <string, byte[]>((long)this.GetHashCode(), "{0}: Unknown sharing provider guid: {1}", messageItem.Session.UserLegacyDN, array); throw new NotSupportedSharingMessageException(); } ExTraceGlobals.SharingTracer.TraceDebug <string, SharingProvider>((long)this.GetHashCode(), "{0}: Find provider {1} that is specified in message.", messageItem.Session.UserLegacyDN, sharingProvider); if (sharingProvider == SharingProvider.SharingProviderPublish) { ExTraceGlobals.SharingTracer.TraceDebug <string, SharingProvider>((long)this.GetHashCode(), "{0}: Read from message x-properties for provider {1}.", messageItem.Session.UserLegacyDN, sharingProvider); this.ReadFromMessageXProperties(messageItem); } if (isDraft || sharingProvider != SharingProvider.SharingProviderPublish) { ExTraceGlobals.SharingTracer.TraceDebug <string, SharingProvider>((long)this.GetHashCode(), "{0}: Read from message properties for provider {1}.", messageItem.Session.UserLegacyDN, sharingProvider); this.ReadFromMessageProperties(messageItem); } if (this.context.SharingMessageType == SharingMessageType.Unknown && !isDraft) { ExTraceGlobals.SharingTracer.TraceError <string>((long)this.GetHashCode(), "{0}: SharingMessageType is unknown", messageItem.Session.UserLegacyDN); throw new InvalidSharingMessageException("SharingFlavor"); } this.context.AvailableSharingProviders.Clear(); if (isDraft && !this.context.SharingMessageType.IsResponseToRequest) { SharingProvider[] array2 = null; using (Folder folder = Folder.Bind(messageItem.Session, this.context.FolderId)) { array2 = SharingProvider.GetCompatibleProviders(sharingProvider, folder); } foreach (SharingProvider sharingProvider2 in array2) { ExTraceGlobals.SharingTracer.TraceDebug <string, SharingProvider>((long)this.GetHashCode(), "{0}: Find compatible provider {1}.", messageItem.Session.UserLegacyDN, sharingProvider2); this.context.AvailableSharingProviders.Add(sharingProvider2, null); } return; } this.context.AvailableSharingProviders.Add(sharingProvider, null); }
public override IRgb ToRgb() { return(HexConverter.ToColor(this)); }
internal void SaveIntoMessageXProperties(MessageItem messageItem, bool isClear) { SharingProvider sharingProviderPublish = SharingProvider.SharingProviderPublish; messageItem.SetOrDeleteProperty(InternalSchema.XSharingProviderGuid, isClear ? null : HexConverter.ByteArrayToHexString(sharingProviderPublish.Guid.ToByteArray())); messageItem.SetOrDeleteProperty(InternalSchema.XSharingProviderName, isClear ? null : sharingProviderPublish.Name); messageItem.SetOrDeleteProperty(InternalSchema.XSharingProviderUrl, isClear ? null : sharingProviderPublish.Url); messageItem.SetOrDeleteProperty(InternalSchema.XSharingCapabilities, isClear ? null : string.Format("{0:X}", 521)); messageItem.SetOrDeleteProperty(InternalSchema.XSharingFlavor, isClear ? null : string.Format("{0:X}", 784)); messageItem.SetOrDeleteProperty(InternalSchema.XSharingRemoteType, isClear ? null : this.context.DataType.PublishName); messageItem.SetOrDeleteProperty(InternalSchema.XSharingLocalType, isClear ? null : this.context.FolderClass); messageItem.SetOrDeleteProperty(InternalSchema.XSharingRemoteName, isClear ? null : this.context.FolderName); messageItem.SetOrDeleteProperty(InternalSchema.XSharingBrowseUrl, isClear ? null : this.context.BrowseUrl.ToString()); messageItem.SetOrDeleteProperty(InternalSchema.XSharingRemotePath, isClear ? null : this.context.ICalUrl.ToString()); messageItem.SetOrDeleteProperty(InternalSchema.XSharingInstanceGuid, isClear ? null : HexConverter.ByteArrayToHexString(Guid.NewGuid().ToByteArray())); }
public void EvenNumberDigitWorks() { HexConverter converter = new HexConverter(); Assert.AreEqual(12, converter.ToBytes("694170706c792052756c6573").Length); }