Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
1
Question by Nidre · Sep 16, 2013 at 07:53 PM · windows store appwindows phone 8encryptionwp8

Windows Store App Encryption

Is any one knows an alternative to System.Security.Cryptography for Windows Store App ?

I am currently using RijndaelManaged,CipherMode classes and ICryptoTransform interface from this library.

Only alternative i could find was Windows.Security.Cryptography and this is not available in Mono or at least Unity(As name states i believe this library is Windows only).

My Code is something like that if it helps,

     public static string Encrypt(string toEncrypt, Byte[] keyArray)
     {
         //byte[] keyArray = UTF8Encoding.UTF8.GetBytes("!'jsdflkj%+sklj;i#$99skdjksdjk");
         // 256-AES key
         try
         {
 
             byte[] toEncryptArray = UTF8Encoding.UTF8.GetBytes(toEncrypt);
             using (RijndaelManaged rDel = new RijndaelManaged())
             {
                 rDel.Key = keyArray;
                 rDel.Mode = CipherMode.CBC;
                 // http://msdn.microsoft.com/en-us/library/system.security.cryptography.ciphermode.aspx
                 //rDel.Padding = PaddingMode.PKCS7;
                 // better lang support
                 ICryptoTransform cTransform = rDel.CreateEncryptor(keyArray, IVa);
                 byte[] resultArray = cTransform.TransformFinalBlock(toEncryptArray, 0, toEncryptArray.Length);
                 cTransform.Dispose();
                 return Convert.ToBase64String(resultArray, 0, resultArray.Length);
             }
         }
         catch (Exception ex)
         {
             UnityEngine.Debug.LogError(ex);
             return null;
         }
     }
 
     public static string Decrypt(string toDecrypt, Byte[] keyArray)
     {
         //byte[] keyArray = UTF8Encoding.UTF8.GetBytes("(kl4^+lsktýo1283746:#$iþsdsdsl");
         // AES-256 key
         try
         {
             byte[] toDecryptArray = Convert.FromBase64String(toDecrypt);
             using (RijndaelManaged rDel = new RijndaelManaged())
             {
                 rDel.Key = keyArray;
                 rDel.Mode = CipherMode.CBC;
                 // http://msdn.microsoft.com/en-us/library/system.security.cryptography.ciphermode.aspx
                 //rDel.Padding = PaddingMode.PKCS7;
                 // better lang support
                 ICryptoTransform cTransform = rDel.CreateDecryptor(keyArray,IVa);
                 byte[] resultArray = cTransform.TransformFinalBlock(toDecryptArray, 0, toDecryptArray.Length);
                 cTransform.Dispose();
                 return UTF8Encoding.UTF8.GetString(resultArray);
             }
         }
         catch //(Exception ex)
         {
             //UnityEngine.Debug.LogError(ex);
             return null;
         }
     }
Comment
Add comment · Show 1
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Nidre · Nov 21, 2013 at 08:55 AM 0
Share

Any idea ?

2 Replies

· Add your reply
  • Sort: 
avatar image
1

Answer by CanisLupus · Jun 22, 2014 at 04:35 PM

I don't know an exact equivalent of your code, but you CAN use classes in Windows.Security.Cryptography, even though they are not available in Mono. When you press "build" in Unity to start a Windows Store App build, Unity uses a .NET compiler on your Windows Kit folders (not the one it uses normally), and that compiler knows the classes and libraries in Metro apps (such as Windows.Security.Cryptography).

As for them existing in Windows only, that is true, but you can use #if defines in your scripts to handle code for different platforms:

 #if NETFX_CORE
 // code for Windows 8 here
 #else
 // code for other platforms
 #endif

If what you are after is encrypting and decrypting a string, you can find several examples online in MSDN (using Windows.Security.Cryptography), although I cannot guarantee that it will be easy to find code equivalent to your existing one :( This is relevant if you want to be able to decrypt strings that were encrypted with your current code, for example.

If you want to encrypt and decrypt a string to/from a file, using authenticated encryption (the user cannot change the encrypted data), check this question and answer on StackOverflow. Note that it is certainly not equivalent to your current methods (even if only for the presence of authenticated encryption).

Comment
Add comment · Show 2 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Nidre · Jun 23, 2014 at 06:12 AM 0
Share

Once we will return back working on our Windows $$anonymous$$obile builds i will try definitely try this out.

avatar image CanisLupus · Jun 23, 2014 at 11:43 AM 0
Share

If you have problems in the future, related to this question/answer, comment here. Note that Windows Phone builds will not activate NETFX_CORE, but only UNITY_WP8. Nevertheless, you shouldn't need specific code for Windows Phone, as problems with nonexistent classes/methods happen generally in Windows Store apps (which do not include Windows Phone, although the name might be confusing). But I'm not a Windows Phone developer, so take that with a grain of salt :)

avatar image
0

Answer by B_Manx · Dec 08, 2013 at 04:43 PM

Don't use encryption. your code is easily decompiled in windows 8. write apps as though you are writing them for a browser which lets users easily decompile and see your code. so SSL certificate for communication is your best choice.

Comment
Add comment · Show 2 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Nidre · Dec 09, 2013 at 06:44 AM 0
Share

This is not for communication,this is to save local values such as Score etc... etc... I know libraries, apps can be decoded if you try hard enough. The point here is to prevent as much as people from cheating. So i would like to use Encryption of some kind on Windows Phones too.

avatar image Garth-Smith · May 09, 2014 at 11:20 PM 0
Share

I ran into the same thing. I'm encrypting a save file just to discourage cheating. If someone wants to decompile our save data format, they can go ahead and do it!

So anyone figure out what encryption classes we can use for the Windows Store?

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

18 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Can't run game on Windows Metro becouse of error with dll's 1 Answer

Any way around a known issue when deploying to WP8? Number at start of project. 1 Answer

My game doesn't show up when searching for it by name on the Windows Phone Store 0 Answers

When I build Windows Phone version this error may Occur 0 Answers

Application.openURL crash in Universal App 0 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges