Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- void Main()
- {
- var str = @"8645F8A9-DF41-482A-9C8A-3197FD77A071,0F0A911E-ABF8-444E-99C6-3849325482D4,F4EB1F14-25F7-4014-AAB7-ACFB49CA9DAD";
- var asBase64Str = GuidsToBase64(str);
- // (asBase64.Length == 64) == true;
- var backToGuids = Base64ToGuids(Convert.FromBase64String(asBase64Str));
- backToGuids.Dump();
- }
- static string GuidsToBase64(string guids)
- {
- var splitted = guids.Split(',');
- var asBytes = splitted.Select(Guid.Parse).SelectMany(x => x.ToByteArray()).ToArray();
- return Convert.ToBase64String(asBytes);
- }
- static IEnumerable<Guid> Base64ToGuids(byte[] data)
- {
- var numOfGuids = 3;
- var asStream = new MemoryStream(data);
- for (var i = 0; i < numOfGuids; i++)
- {
- var guidBytes = new byte[16];
- asStream.Read(guidBytes, 0, 16);
- yield return new Guid(guidBytes);
- }
- }
Add Comment
Please, Sign In to add comment