java - Encrypted data length is very large with RSA -


i want encrypted data have same length original text, because must respect constraint of length. using bouncycastle.

here's code generate keys pair:

keypairgenerator keygen = keypairgenerator.getinstance("rsa"); keygen.initialize(512); keypair keypair = keygen.genkeypair(); publickey pub = keypair.getpublic(); byte[] pubs = pub.getencoded(); 

and here's code encrypt:

cipher cipher = cipher.getinstance("rsa/ecb/pkcs1padding"); publickey pk = keyfactory.getinstance("rsa").generatepublic(new x509encodedkeyspec(pubs)); cipher.init(cipher.encrypt_mode, pk); byte[] cipherbytes = cipher.dofinal(plainarray); 

the encoded data large, can make small original data ?

nothing, @ least not regarding rsa. rsa requires amount of padding secure, , data seen random data compression method, cannot compress either.

of course, should not directly encrypt data directly using rsa, should encrypt random session/data key instead. then, have encrypted session key overhead.

you can remove bits asymmetric encrypted data/key using elliptic curve cryptography (the output of double key size minimum, key sizes smaller achieve same level of security). ec cryptography not meek though, has lots of complexity.

512 bit rsa considered insecure way. use 1024 minimum or keep ecrypt ii or nist recommendations listed @ http://www.keylength.com/ .


Comments

Popular posts from this blog

django - How can I change user group without delete record -

java - Need to add SOAP security token -

java - EclipseLink JPA Object is not a known entity type -