use of org.mozilla.jss.util.NativeEnclosure in project jss by dogtagpki.
the class PK11KeyWrapper method wrap.
@Override
public byte[] wrap(SymmetricKey toBeWrapped) throws InvalidKeyException, IllegalStateException, TokenException {
if (state != WRAP) {
throw new IllegalStateException();
}
if (algorithm == KeyWrapAlgorithm.PLAINTEXT) {
throw new InvalidKeyException("plaintext wrapping not supported");
}
checkWrappee(toBeWrapped);
if (symKey != null) {
assert (privKey == null && pubKey == null);
return nativeWrapSymWithSym(token, toBeWrapped, symKey, algorithm, IV);
}
assert (pubKey != null && privKey == null && symKey == null);
NativeProxy params = null;
long params_size = 0;
if (parameters != null) {
try {
((NativeEnclosure) parameters).open();
params = ((NativeEnclosure) parameters).mPointer;
params_size = ((NativeEnclosure) parameters).mPointerSize;
} catch (Exception e) {
throw new TokenException(e.getMessage(), e);
}
}
try {
return nativeWrapSymWithPub(token, toBeWrapped, pubKey, algorithm, params, params_size);
} finally {
if (parameters != null) {
try {
((NativeEnclosure) parameters).close();
} catch (Exception e) {
throw new TokenException(e.getMessage(), e);
}
}
}
}
use of org.mozilla.jss.util.NativeEnclosure in project jss by dogtagpki.
the class PK11KeyWrapper method unwrapSymmetric.
private SymmetricKey unwrapSymmetric(byte[] wrapped, SymmetricKey.Type type, int usageEnum, int keyLen) throws TokenException, IllegalStateException, InvalidAlgorithmParameterException {
if (state != UNWRAP) {
throw new IllegalStateException();
}
if ((!algorithm.isPadded()) && (type == SymmetricKey.RC4)) {
if (keyLen <= 0) {
throw new InvalidAlgorithmParameterException("RC4 keys wrapped in unpadded algorithms need key length" + " specified when unwrapping");
}
} else {
// Don't use the key length
// keyLen = 0;
}
/* Since we DONT want permanent,make the temporary arg true */
boolean temporary = true;
if (algorithm == KeyWrapAlgorithm.PLAINTEXT) {
return nativeUnwrapSymPlaintext(token, wrapped, algFromType(type), usageEnum, temporary);
}
if (symKey != null) {
assert (pubKey == null && privKey == null);
return nativeUnwrapSymWithSym(token, symKey, wrapped, algorithm, algFromType(type), keyLen, IV, usageEnum, temporary);
}
assert (privKey != null && pubKey == null && symKey == null);
NativeProxy params = null;
long params_size = 0;
if (parameters != null) {
try {
((NativeEnclosure) parameters).open();
params = ((NativeEnclosure) parameters).mPointer;
params_size = ((NativeEnclosure) parameters).mPointerSize;
} catch (Exception e) {
throw new TokenException(e.getMessage(), e);
}
}
try {
return nativeUnwrapSymWithPriv(token, privKey, wrapped, algorithm, algFromType(type), keyLen, params, params_size, usageEnum);
} finally {
if (parameters != null) {
try {
((NativeEnclosure) parameters).close();
} catch (Exception e) {
throw new TokenException(e.getMessage(), e);
}
}
}
}
Aggregations