コード例 #1
0
        public void TestShortGzipUtility()
        {
            string gzipString = GzipUtility.Zip(this.ShortInputString);
            //Assert.IsTrue(gzipString.Length < this.ShortInputString.Length);
            string originalString = GzipUtility.Unzip(gzipString);

            Assert.AreEqual(this.ShortInputString, originalString);
        }
コード例 #2
0
 /// <summary>
 /// Read the package and get its content
 /// https://github.com/AlenToma/EntityWorker.Core/blob/master/Documentation/Package.md
 /// </summary>
 /// <param name="package"></param>
 /// <returns></returns>
 public T GetPackage <T>(byte[] package) where T : PackageEntity
 {
     try
     {
         var uncompressedFile = GzipUtility.Decompress(package);
         var packageString    = System.Text.Encoding.UTF8.GetString(new ByteCipher(GlobalConfiguration.PackageDataEncode_Key, DataCipherKeySize.Key_128).Decrypt(uncompressedFile));
         return(packageString.FromJson <T>());
     }
     catch (Exception exception)
     {
         throw new EntityException($"Error the package structure is not valid.\n Orginal exception\n{exception.Message}");
     }
 }
コード例 #3
0
        /// <summary>
        /// Create Protected package that contain files or data for backup purpose or moving data from one location to another.
        /// Note that this package can only be readed by EntityWorker.Core
        /// https://github.com/AlenToma/EntityWorker.Core/blob/master/Documentation/Package.md
        /// </summary>
        /// <param name="package"></param>
        /// <returns></returns>
        public byte[] CreatePackage <T>(T package) where T : PackageEntity
        {
            if (package == null)
            {
                throw new EntityException("Package cant be null");
            }

            var packageString = package.ToJson();

            var bytes = System.Text.Encoding.UTF8.GetBytes(packageString);

            return(GzipUtility.Compress(new ByteCipher(GlobalConfiguration.PackageDataEncode_Key, DataCipherKeySize.Key_128).Encrypt(bytes)));
        }
コード例 #4
0
 /// <summary>
 /// Create Protected package that contain files or data for backup purpose or moving data from one location to another.
 /// Note that this package can only be readed by EntityWorker.Core
 /// https://github.com/AlenToma/EntityWorker.Core/blob/master/Documentation/Package.md
 /// </summary>
 /// <param name="package"></param>
 /// <returns></returns>
 public byte[] CreatePackage <T>(T package) where T : PackageEntity
 {
     if (package == null)
     {
         throw new EntityException("Package cant be null");
     }
     using (var mem = new MemoryStream())
     {
         using (var db = new LiteDB.LiteDatabase(mem))
         {
             var packageCollection = db.GetCollection <T>("Packages");
             packageCollection.Insert(package);
             return(GzipUtility.Compress(new ByteCipher(GlobalConfiguration.PackageDataEncode_Key, DataCipherKeySize.Key_128).Encrypt(mem.ToArray())));
         }
     }
 }
コード例 #5
0
        public override UserProfile GetUserProfileByToken(string token)
        {
            var jsonToken = this.JwtSecurityTokenHandler.ReadToken(token) as JwtSecurityToken;

            return(new UserProfile
            {
                Tenant = this.GetClaimValue(jsonToken.Claims, TokenClaims.Tenant),
                Id = this.GetClaimValue(jsonToken.Claims, TokenClaims.Id),
                Issuer = this.GetClaimValue(jsonToken.Claims, TokenClaims.Issuer),
                Audience = this.GetClaimValue(jsonToken.Claims, TokenClaims.Audience),
                Name = this.GetClaimValue(jsonToken.Claims, ClaimTypes.Name),
                Email = this.GetClaimValue(jsonToken.Claims, ClaimTypes.Email),
                Roles = this.GetClaimValues(jsonToken.Claims, ClaimTypes.Role),
                Apis = JsonUtility.Deserialize <IList <string> >(GzipUtility.Unzip(this.GetClaimValue(jsonToken.Claims, TokenClaims.Api))),
                Modules = JsonUtility.Deserialize <IList <string> >(GzipUtility.Unzip(this.GetClaimValue(jsonToken.Claims, TokenClaims.Module)))
            });
        }
コード例 #6
0
 /// <summary>
 /// Read the package and get its content
 /// https://github.com/AlenToma/EntityWorker.Core/blob/master/Documentation/Package.md
 /// </summary>
 /// <param name="package"></param>
 /// <returns></returns>
 public T GetPackage <T>(byte[] package) where T : PackageEntity
 {
     try
     {
         var uncompressedFile = GzipUtility.Decompress(package);
         using (var msi = new MemoryStream(new ByteCipher(GlobalConfiguration.PackageDataEncode_Key, DataCipherKeySize.Key_128).Decrypt(uncompressedFile)))
         {
             // now read the file
             using (var db = new LiteDB.LiteDatabase(msi))
             {
                 var packageCollection = db.GetCollection <T>("Packages");
                 return(packageCollection.FindOne(x => x.Data != null || x.Files != null));
             }
         }
     }
     catch (Exception exception)
     {
         throw new EntityException($"Error the package structure is not valid.\n Orginal exception\n{exception.Message}");
     }
 }