use of io.getlime.security.powerauth.crypto.lib.encryptor.model.NonPersonalizedEncryptedMessage in project powerauth-restful-integration by lime-company.
the class PowerAuthNonPersonalizedEncryptor method encrypt.
public ObjectResponse<NonPersonalizedEncryptedPayloadModel> encrypt(byte[] originalData) {
if (originalData == null) {
return null;
}
NonPersonalizedEncryptedMessage message = encryptor.encrypt(originalData);
if (message == null) {
// this will happen only in case of an unlikely randomness error, or if keys are corrupted
return null;
}
NonPersonalizedEncryptedPayloadModel responseObject = new NonPersonalizedEncryptedPayloadModel();
responseObject.setApplicationKey(BaseEncoding.base64().encode(message.getApplicationKey()));
responseObject.setEphemeralPublicKey(BaseEncoding.base64().encode(message.getEphemeralPublicKey()));
responseObject.setSessionIndex(BaseEncoding.base64().encode(message.getSessionIndex()));
responseObject.setAdHocIndex(BaseEncoding.base64().encode(message.getAdHocIndex()));
responseObject.setMacIndex(BaseEncoding.base64().encode(message.getMacIndex()));
responseObject.setNonce(BaseEncoding.base64().encode(message.getNonce()));
responseObject.setMac(BaseEncoding.base64().encode(message.getMac()));
responseObject.setEncryptedData(BaseEncoding.base64().encode(message.getEncryptedData()));
return new ObjectResponse<>(responseObject);
}
use of io.getlime.security.powerauth.crypto.lib.encryptor.model.NonPersonalizedEncryptedMessage in project powerauth-restful-integration by lime-company.
the class PowerAuthNonPersonalizedEncryptor method decrypt.
public byte[] decrypt(ObjectRequest<NonPersonalizedEncryptedPayloadModel> request) {
if (request == null) {
return null;
}
NonPersonalizedEncryptedPayloadModel requestObject = request.getRequestObject();
if (requestObject == null) {
return null;
}
NonPersonalizedEncryptedMessage message = new NonPersonalizedEncryptedMessage();
message.setApplicationKey(BaseEncoding.base64().decode(requestObject.getApplicationKey()));
message.setEphemeralPublicKey(BaseEncoding.base64().decode(requestObject.getEphemeralPublicKey()));
message.setSessionIndex(BaseEncoding.base64().decode(requestObject.getSessionIndex()));
message.setAdHocIndex(BaseEncoding.base64().decode(requestObject.getAdHocIndex()));
message.setMacIndex(BaseEncoding.base64().decode(requestObject.getMacIndex()));
message.setNonce(BaseEncoding.base64().decode(requestObject.getNonce()));
message.setMac(BaseEncoding.base64().decode(requestObject.getMac()));
message.setEncryptedData(BaseEncoding.base64().decode(requestObject.getEncryptedData()));
return encryptor.decrypt(message);
}
Aggregations