Encrypting a shared key on the Android/Java platform -
i´m new both android platform , encryption, bear me. need call webservice requires me encrypt parameter before calling it. have received specification reads:
"we use aes encrypt. settings encryption follow:
key: publickey12345678910
number of bits: 128
padding: pkcs #7
cipher: cipher block chaining (cbc)"
now, problem lack of basic understanding of encryption process. have public key, do it? have tried find answer online efforts seem result in either wrong encrypted key or "invalidkeylengthexception, key not 128, 196 or 256 bits" (or in general direction). recent effort, borrows heavily answer here on stack, looks this:
string input = "theparameteriwanttoencrypt"; string secretid = "publickey12345678910"; char[] inputchars = input.tochararray(); char[] pswchars = secretid.tochararray(); secretkeyfactory factory = secretkeyfactory.getinstance("pbewithmd5anddes", new bouncycastleprovider()); keyspec spec = new pbekeyspec(pswchars); secretkey tmp = factory.generatesecret(spec); secretkey secret = new secretkeyspec(tmp.getencoded(), "aes"); cipher cipher = cipher.getinstance("aes/cbc/pkcs7padding"); cipher.init(cipher.encrypt_mode, secret); algorithmparameters params = cipher.getparameters(); byte[] iv = params.getparameterspec(ivparameterspec.class).getiv(); byte[] ciphertext = cipher.dofinal(input.getbytes()); system.out.println(new string(ciphertext)); could explain me in order things in supplied specification? also, code implementing behavior on java/android platform obliged.
forget, moment, implementation details, , let's focus on things @ higher level. if perform encryption in manner, private key stored somewhere in program or in data used program in way extracted, compromising encryption.
by contrast, if use https (which standard way create encrypted session), there well-tested , well-studied process whereby asymmetric cipher used establish private keys used create encrypted channel (usually using 128-bit aes encryption).
you should push on whoever providing webservice offer on standard https connection encryption, rather relying on encrypting individual fields this.
Comments
Post a Comment