?
Solved

create javax.crypto.SecretKey from byte array !

Posted on 2005-05-10
8
Medium Priority
?
719 Views
Last Modified: 2012-08-14
i have a byte array (SecretKey Value), and i know what algorithm that SecretKey is for.
So how can i create javax.crypto.SecretKey from that byte array and algorith String.

exactly, my problem is that: i use secretkey of a KerberosTicket to encrypt my SOAP Message.
To encrypt SOAPMsg i use XMLCipher obj of XMLSecurity (from apache) obj.
To init XMLCipher i must supply a SecretKey.
So i must create a javax.crypto.SecretKey from byte array which i get from KerberosTicket but how ?

Anybody help ?
0
Comment
Question by:hoaivan
  • 3
  • 2
  • 2
  • +1
8 Comments
 
LVL 92

Accepted Solution

by:
objects earned 900 total points
ID: 13974906
0
 
LVL 15

Expert Comment

by:aozarov
ID: 13974985
If you have already the KerberosTicket then just call its  getSessionKey()  which will return you the SecretKey.
0
 
LVL 16

Assisted Solution

by:gnoon
gnoon earned 600 total points
ID: 13975393
To form SecretKey from raw bytes and algorithm, try this

 SecretKeySpec keySpec = new SecretKeySpec(rawKeyBytes, algorithmString);
 SecretKey key = null;
 try
 {
     SecretKeyFactory.getInstance(algorithmString).generateSecret(keySpec);
 }
 catch(Exception e)
 {
     e.printStackTrace();
 }
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
LVL 16

Expert Comment

by:gnoon
ID: 13975400
SecretKeyFactory.getInstance(algorithmString).generateSecret(keySpec);

should be

key = SecretKeyFactory.getInstance(algorithmString).generateSecret(keySpec);
0
 
LVL 15

Expert Comment

by:aozarov
ID: 13977444
Hi hoaivan,
Just for the benifit of my knowledge. I though you are using Kerberos and you got the KerberosTicket, am I wrong?
If not then how do you know which algorithm the Kerberos used for this seesion based secret key (if you want to use SecretKeyFactory or descide upon DES)?
0
 

Author Comment

by:hoaivan
ID: 13979200
format of a EncryptionKey in Kerberos: you see the keytype there

          EncryptionKey ::=   SEQUENCE {
                              keytype[0]    INTEGER,
                              keyvalue[1]   OCTET STRING
          }

and

---------------+-----------+----------+----------------+---------------
Encryption type|etype value|block size|minimum pad size|confounder size
---------------+-----------+----------+----------------+---------------
NULL                0            1              0              0
des-cbc-crc         1            8              4              8
des-cbc-md4         2            8              0              8
des-cbc-md5         3            8              0              8
0
 
LVL 15

Expert Comment

by:aozarov
ID: 13979853
Ok, so I guess I didn't understand you well as I though you already have the KerberosTicket and you wanted to get the PK encapsulated in it. "i use secretkey of a KerberosTicket to encrypt my SOAP Message."
 
0
 

Author Comment

by:hoaivan
ID: 13983057
ya, i got secretkey encapsulated in KerberosTicket but just an array of byte.
When do sign/encrypt with XMLSecurity, it need that secretkey as an instance of javax.crypto.SecretKey.

=> SecretKey sk = new SecretKeySpec(bytArr, strAlgo);

:)
0

Featured Post

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
In this post we will learn how to make Android Gesture Tutorial and give different functionality whenever a user Touch or Scroll android screen.
This theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.
This video teaches viewers about errors in exception handling.
Suggested Courses
Course of the Month14 days, 22 hours left to enroll

839 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question