Featured post

c# - Usage of Server Side Controls in MVC Frame work -

i using asp.net 4.0 , mvc 2.0 web application. project requiremrnt have use server side control in application not possibl in noraml case. ideally want use adrotator control , datalist control. i saw few samples , references in codepleax mvc controllib howwver found less useful. can tell how utilize theese controls in asp.net application along mvc. note: please provide functionalities related adrotator , datalist controls not equivalent functionalities thanks in advace. mvc pages not use normal .net solution makes use of normal .net components impossible. a normal .net page use event driven solution call different methods service side mvc use actions , view completly different way handle things. also, mvc not use viewstate normal .net controlls require. found article discussing mixing of normal .net , mvc.

Equivalent to CryptoStream .NET in Java? -


i have encrypted string in visual basic. net 2008, functions encrypt , decrypt following:

imports system.security.cryptography   public shared function encriptar(byval strvalor string) string     dim strencrkey string = "key12345"      dim bykey() byte = {}     dim iv() byte = {&h12, &h34, &h56, &h78, &h90, &hab, &hcd, &hef}     try         bykey = system.text.encoding.utf8.getbytes(strencrkey)         dim des new descryptoserviceprovider         dim inputbytearray() byte = encoding.utf8.getbytes(strvalor)         dim ms new memorystream         dim cs new cryptostream(ms, des.createencryptor(bykey, iv), cryptostreammode.write)         cs.write(inputbytearray, 0, inputbytearray.length)         cs.flushfinalblock()         return convert.tobase64string(ms.toarray())     catch ex exception         return ""     end try end function  public shared function desencriptar(byval strvalor string) string     dim sdecrkey string = "key12345"      dim bykey() byte = {}     dim iv() byte = {&h12, &h34, &h56, &h78, &h90, &hab, &hcd, &hef}     dim inputbytearray(strvalor.length) byte     try         bykey = system.text.encoding.utf8.getbytes(sdecrkey)         dim des new descryptoserviceprovider         if trim(strvalor).length = 0             throw new exception("password no debe estar en blanco")         end if         inputbytearray = convert.frombase64string(strvalor)         dim ms new memorystream         dim cs new cryptostream(ms, des.createdecryptor(bykey, iv), cryptostreammode.write)         cs.write(inputbytearray, 0, inputbytearray.length)         cs.flushfinalblock()         dim encoding system.text.encoding = system.text.encoding.utf8         return encoding.getstring(ms.toarray(), 0, ms.toarray.count)     catch ex exception         return ""     end try end function 

for example word "android" encrypted function gives me result "b3xogi/qfsc="

now need decrypt string "b3xogi/qfsc=" java, same key, "key12345", , result should "android"...anyone know how this?

thanks in advance.

using apache commons codec hex , base64 encoding/decoding, can use following code:

keyspec ks = new deskeyspec("key12345".getbytes("utf-8")); secretkey key = secretkeyfactory.getinstance("des").generatesecret(ks);  ivparameterspec iv = new ivparameterspec(         hex.decodehex("1234567890abcdef".tochararray()));  cipher cipher = cipher.getinstance("des/cbc/pkcs5padding"); cipher.init(cipher.decrypt_mode, key, iv);  byte[] decoded = cipher.dofinal(base64.decodebase64("b3xogi/qfsc="));  system.out.println("decoded: " + new string(decoded, "utf-8")); 

Comments

Popular posts from this blog

c# - Usage of Server Side Controls in MVC Frame work -

cocoa - Nesting arrays into NSDictionary object (Objective-C) -

ios - Very simple iPhone App crashes on UILabel settext -