Skip to Main Content

Java Security

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

.net equivalent tdes encryption/ decryption

843811Aug 21 2007 — edited Aug 29 2007
im totally new to cryptograhy. need help on this as one of my vendor is using .NET to encrypt and descrypt passwd.

.net code is sth like...
    Private Const ENCKEY = "hN+4OG5hLADLKbnLfxuCHcud96EWIRcn"
    Private Const ENCIV = "NTU0eyE3FEE="

    Private mobjCSP As New System.Security.Cryptography.TripleDESCryptoServiceProvider

    Public Function EncryptString_3DES(ByVal strValue As String) As String
        Dim objICrytoT As System.Security.Cryptography.ICryptoTransform
        Dim objMS As System.IO.MemoryStream
        Dim objCryptoStream As System.Security.Cryptography.CryptoStream
        Dim bytData() As Byte

        '//Generate 2 Keys to Generated Encrypted string using 3DES
        mobjCSP.GenerateKey()
        mobjCSP.GenerateIV()

        objICrytoT = mobjCSP.CreateEncryptor(Convert.FromBase64String(ENCKEY), Convert.FromBase64String(ENCIV))
        bytData = System.Text.Encoding.UTF8.GetBytes(strValue)

        '//Crytography Stream to write Encrypted a string
        objMS = New System.IO.MemoryStream
        objCryptoStream = New System.Security.Cryptography.CryptoStream(objMS, objICrytoT, System.Security.Cryptography.CryptoStreamMode.Write)
        objCryptoStream.Write(bytData, 0, bytData.Length)
        objCryptoStream.FlushFinalBlock()
        objCryptoStream.Close()

        Return Convert.ToBase64String(objMS.ToArray())
    End Function
and i tried to write a equivalent java...
	public void cipher() throws NoSuchAlgorithmException, NoSuchPaddingException, InvalidKeyException, IllegalBlockSizeException, InvalidAlgorithmParameterException, BadPaddingException{
		byte [] seed_key = (new String("hN+4OG5hLADLKbnLfxuCHcud96EWIRcn")).getBytes();
		byte [] seed_iv = (new String("NTU0eyE3FEE=")).getBytes();
		
		iv = new javax.crypto.spec.IvParameterSpec(seed_iv);
	        k = KeyGenerator.getInstance("DES").generateKey();


		c= Cipher.getInstance("DES/CBC/PKCS7Padding");
	        c.init(Cipher.ENCRYPT_MODE, k, iv);
		byte[] cipherbyte = c.doFinal(encText.getBytes());
		
		String encodeTxt = new String(Base64.encodeBase64(cipherbyte));

		

		
	}
i got error message
Cannot find any provider supporting DES/CBC/PKCS7Padding

May i know...
is my code doing fine?
what is the default mode and padding for .NET? coz the .net code doesnt specify 1.
and i dont understand what's with the GenerateIV and GenerateKey in , doesnt
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Sep 26 2007
Added on Aug 21 2007
21 comments
496 views