المساعد الشخصي الرقمي

مشاهدة النسخة كاملة : from java to c#



C# Programming
01-28-2013, 01:42 AM
how i can convert this code from java to c#

public static String Dcipher(String encryptedText1) { try { byte[] desKeyData = {(byte) 0x01, (byte) 0x02, (byte) 0x03, (byte) 0x04, (byte) 0x05, (byte) 0x06, (byte) 0x07, (byte) 0x08}; DESKeySpec desKeySpec = new DESKeySpec(desKeyData); SecretKeyFactory keyFactory = SecretKeyFactory.getInstance("DES"); SecretKey key = null; try { key = keyFactory.generateSecret(desKeySpec); } catch (InvalidKeySpecException ex1) { } byte[] initVector = new byte[] {0x10, 0x10, 0x01, 0x04, 0x01, 0x01, 0x01, 0x02}; AlgorithmParameterSpec algParamSpec = new IvParameterSpec( initVector); Cipher m_decrypter = Cipher.getInstance("DES/OFB32/NoPadding"); m_decrypter.init(Cipher.DECRYPT_MODE, key, algParamSpec); byte[] encryptedText = encryptedText1.getBytes(); byte[] decryptedText = m_decrypter.doFinal(encryptedText); return (new String(decryptedText)); } catch (BadPaddingException ex) { ex.printStackTrace(); } catch (IllegalBlockSizeException ex) { ex.printStackTrace(); } catch (InvalidAlgorithmParameterException ex) { ex.printStackTrace(); } catch (InvalidKeyException ex) { ex.printStackTrace(); } catch (NoSuchPaddingException ex) { ex.printStackTrace(); } catch (NoSuchAlgorithmException ex) { ex.printStackTrace(); } return ""; }