Search in sources :

Example 1 with NonPersonalizedEncryptedMessage

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);
}
Also used : NonPersonalizedEncryptedPayloadModel(io.getlime.security.powerauth.rest.api.model.entity.NonPersonalizedEncryptedPayloadModel) ObjectResponse(io.getlime.core.rest.model.base.response.ObjectResponse) NonPersonalizedEncryptedMessage(io.getlime.security.powerauth.crypto.lib.encryptor.model.NonPersonalizedEncryptedMessage)

Example 2 with NonPersonalizedEncryptedMessage

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);
}
Also used : NonPersonalizedEncryptedPayloadModel(io.getlime.security.powerauth.rest.api.model.entity.NonPersonalizedEncryptedPayloadModel) NonPersonalizedEncryptedMessage(io.getlime.security.powerauth.crypto.lib.encryptor.model.NonPersonalizedEncryptedMessage)

Aggregations

NonPersonalizedEncryptedMessage (io.getlime.security.powerauth.crypto.lib.encryptor.model.NonPersonalizedEncryptedMessage)2 NonPersonalizedEncryptedPayloadModel (io.getlime.security.powerauth.rest.api.model.entity.NonPersonalizedEncryptedPayloadModel)2 ObjectResponse (io.getlime.core.rest.model.base.response.ObjectResponse)1