Results 1 to 2 of 2
Thread: decryption equal to c#
- 10-29-2012, 07:07 AM #1
Member
- Join Date
- Oct 2012
- Posts
- 1
- Rep Power
- 0
decryption equal to c#
I have a snopped that works in c#
But it hard to my to convert code to java. Here are my Java tries:Java Code:string cipherText="text to decrypt$%TRTEGRTEhgrtgewfewfewg6tyrjhryth"; string pw="12345678"; IBuffer pwBuffer = CryptographicBuffer.ConvertStringToBinary(pw, BinaryStringEncoding.Utf8); IBuffer saltBuffer = CryptographicBuffer.ConvertStringToBinary(pw, BinaryStringEncoding.Utf8); IBuffer cipherBuffer = CryptographicBuffer.DecodeFromBase64String(cipherText); // Derive key material for password size 32 bytes for AES256 algorithm KeyDerivationAlgorithmProvider keyDerivationProvider = Windows.Security.Cryptography.Core.KeyDerivationAlgorithmProvider.OpenAlgorithm("PBKDF2_SHA1"); // using salt and 1000 iterations KeyDerivationParameters pbkdf2Parms = KeyDerivationParameters.BuildForPbkdf2(saltBuffer, 1000); // create a key based on original key and derivation parmaters CryptographicKey keyOriginal = keyDerivationProvider.CreateKey(pwBuffer); IBuffer keyMaterial = CryptographicEngine.DeriveKeyMaterial(keyOriginal, pbkdf2Parms, 32); CryptographicKey derivedPwKey = keyDerivationProvider.CreateKey(pwBuffer); // derive buffer to be used for encryption salt from derived password key IBuffer saltMaterial = CryptographicEngine.DeriveKeyMaterial(derivedPwKey, pbkdf2Parms, 16); // display the keys - because KeyDerivationProvider always gets cleared after each use, they are very similar unforunately string keyMaterialString = CryptographicBuffer.EncodeToBase64String(keyMaterial); string saltMaterialString = CryptographicBuffer.EncodeToBase64String(saltMaterial); SymmetricKeyAlgorithmProvider symProvider = SymmetricKeyAlgorithmProvider.OpenAlgorithm("AES_CBC_PKCS7"); // create symmetric key from derived password material CryptographicKey symmKey = symProvider.CreateSymmetricKey(keyMaterial); // encrypt data buffer using symmetric key and derived salt material IBuffer resultBuffer = CryptographicEngine.Decrypt(symmKey, cipherBuffer, saltMaterial); byte[] asd; CryptographicBuffer.CopyToByteArray(resultBuffer, out asd); string result = CryptographicBuffer.ConvertBinaryToString(BinaryStringEncoding.Utf8, resultBuffer); return result;
Seems that's impossible to find same algorythm at Java as at C#, or?Java Code:String textTo="text to decrypt$%TRTEGRTEhgrtgewfewfewg6tyrjhryth"; final String kkey="0000000000000000"; final javax.crypto.spec.SecretKeySpec keySpec = new SecretKeySpec(kkey.getBytes(), "AES"); final javax.crypto.Cipher cipher = Cipher.getInstance("AES"); cipher.init(Cipher.ENCRYPT_MODE, keySpec); byte [] encryptedValue = cipher.doFinal(textTo.getBytes()); String aa=new String(encryptedValue); System.out.println(new String(aa)); return aa;
- 10-29-2012, 01:13 PM #2
Re: decryption equal to c#
Snopped? Word of the day.
You're going to have to break the algorithm down into its individual pieces, then figure out how to do each step in Java. What does each line do?How to Ask Questions the Smart Way
Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!
Similar Threads
-
Decryption problem...
By muneeb in forum New To JavaReplies: 0Last Post: 09-13-2011, 10:19 AM -
Decryption problem...
By muneeb in forum Java SoftwareReplies: 0Last Post: 09-13-2011, 10:19 AM -
Encryption and Decryption
By jatinkansagara in forum Advanced JavaReplies: 7Last Post: 06-27-2011, 03:08 PM -
problem about AES Decryption(help me please)
By smart_mody in forum New To JavaReplies: 2Last Post: 09-29-2009, 11:32 PM -
PGP Encryption&Decryption
By Deepa in forum New To JavaReplies: 2Last Post: 07-07-2009, 06:22 AM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks