use of com.github.zhenwei.core.crypto.agreement.kdf.DHKDFParameters in project LinLong-Java by zhenwei1108.
the class BaseAgreementSpi method getSharedSecretBytes.
private byte[] getSharedSecretBytes(byte[] secret, String oidAlgorithm, int keySize) throws NoSuchAlgorithmException {
if (kdf != null) {
if (keySize < 0) {
throw new NoSuchAlgorithmException("unknown algorithm encountered: " + oidAlgorithm);
}
byte[] keyBytes = new byte[keySize / 8];
if (kdf instanceof DHKEKGenerator) {
if (oidAlgorithm == null) {
throw new NoSuchAlgorithmException("algorithm OID is null");
}
ASN1ObjectIdentifier oid;
try {
oid = new ASN1ObjectIdentifier(oidAlgorithm);
} catch (IllegalArgumentException e) {
throw new NoSuchAlgorithmException("no OID for algorithm: " + oidAlgorithm);
}
DHKDFParameters params = new DHKDFParameters(oid, keySize, secret, ukmParameters);
kdf.init(params);
} else {
KDFParameters params = new KDFParameters(secret, ukmParameters);
kdf.init(params);
}
kdf.generateBytes(keyBytes, 0, keyBytes.length);
Arrays.clear(secret);
return keyBytes;
} else {
if (keySize > 0) {
byte[] keyBytes = new byte[keySize / 8];
System.arraycopy(secret, 0, keyBytes, 0, keyBytes.length);
Arrays.clear(secret);
return keyBytes;
}
return secret;
}
}
Aggregations