ModuleSharedFunctions.cs 730 Bytes
using System;
using System.Collections.Generic;
using System.Linq;
using Sungero.Core;
using Sungero.CoreEntities;
using System.Text.RegularExpressions;
using System.Text;

namespace DirRX.Storage.Shared
{
  public class ModuleFunctions
  {
    public bool IsBase64Encoded(byte[] data)
    {
      var str = Encoding.Default.GetString(data);
      str = str.Trim();
      return (str.Length % 4 == 0) && Regex.IsMatch(str, @"^[a-zA-Z0-9\+/]*={0,3}$", RegexOptions.None);
    }
    
    public byte[] DecodeFromBase64(byte[] data)
    {
      if (!IsBase64Encoded(data))
        return data;
      
      var result = Convert.FromBase64String(Encoding.Default.GetString(data));
      return DecodeFromBase64(result);
    }
  }
}