java


Android AES/ECB/PKCS7PADDING generate key bouncy castle


I want to generate Random key using AES/ECB/PKCS7PADDING but java does not support PKCS7 padding and in my algo I have to use the same padding, bouncy castle does support PKCS7PADDING but I am unable to understand how to generate key using that
My code :
Security.addProvider(new BouncyCastleProvider());
private byte[] generateSessionKey() throws NoSuchAlgorithmException, NoSuchProviderException {
KeyGenerator kgen = KeyGenerator.getInstance("AES/ECB/PKCS7PADDING", "BC");
kgen.init(SYMMETRIC_KEY_SIZE);
SecretKey key = kgen.generateKey();
return key.getEncoded();
}
I am receiving error of no such algorithm
Key generation for AES does not have to do anything with padding. Padding is required for some modes of operation such as ECB and CBC. But the key itself doesn't rely on the mode or the padding. So you should just use:
KeyGenerator kgen = KeyGenerator.getInstance("AES", "BC");
which will undoubtedly work.
Do not use PKCS#7 padding, substitute "PKCS5Padding" for "PKCS7Padding".
Please take a look here to understand the difference between the padding mechanisms and here for the difference in Java.
I guess Android is using a stripped down Bouncy Castle provider (it was one of the reasons that SpongyCastle was lounged), which would explain the differences between Android and the Java SE provider.

Related Links

Installation failed on Android Gingerbread and Froyo - INSTALL_FAILED_DEXOPT
Project facet WebSphere Web (Co-existence) version 8.0 is not supported
Get the average from xml list
How to copy paste from Ms word to TextView with keeping same format essentially color and bold
How do i know if my application is running in weblogic in debug mode?
For loop is acting differently
Keypoint matching just works two times…? (java opencv)
Transaction errors in JBoss AS 7.1 with MySQL database
Difference in output between similar while loop and do while loop?
Validate routing number
Unfortunately, app name has stopped in Eclipse
How to initialize Condition object without explicitly assigning?
Partial Data deletes using Java SQL Hibernate
Velocity print values and their keys
java code to read all .xml files in a folder and update each xml file data in a table
Unknown mappedBy in: com.omnypay.dao.bo.CloudSvrUser.UserPwdList, referenced property unknown: java.util.List.user

Categories

HOME
image
appx
view
google-project-tango
blueprintjs
cloudkit
google-cloud-ml
remote-access
circuit
iron-router
jsdoc
bootstrap-tour
lcd
firebase-crash-reporting
java-7
angular2-aot
fish
chromebook
url-scheme
user-interaction
traffic
uninstall
fgetcsv
greendao
linkerd
web-api-testing
fifo
objectanimator
quote
delicious-api
flink-streaming
bluestacks
phonegap
exuberant-ctags
catel
gtrendsr
http-referer
dartium
hot-module-replacement
starteam
objectlistview
leading-zero
mapzen
galen
eigenvalue
slick-3.0
businessworks
xml-documentation
pango
python-webbrowser
lift-json
python-cryptography
django-scheduler
mediaelement
background-service
android-fonts
nxt
phishing
qcustomplot
associative-array
browser-link
jms2
ruby-2.2
ionic
pretty-print
clipperlib
formatjs
android-nested-fragment
socketexception
xcode-6.2
gulp-less
issuu
jubula
hippomocks
openlaszlo
pyhdf
commoncrypto
google-cloud-save
selected
mt
multipage
appconkit
reddot
mod-auth
appender
asp.net-mvc-areas
ncqrs
simpletest
yagni
paul-graham

Resources

Mobile Apps Dev
Database Users
javascript
java
csharp
php
android
MS Developer
developer works
python
ios
c
html
jquery
RDBMS discuss
Cloud Virtualization
Database Dev&Adm
javascript
java
csharp
php
python
android
jquery
ruby
ios
html
Mobile App
Mobile App
Mobile App