diff --git a/src/EventSubscriber/CspSubscriber.php b/src/EventSubscriber/CspSubscriber.php
index 7d90180fa33bfc6b243b1f6a8e46a5829ea3f63d..90a1856ef5835784c873bc671c8ac62d2e6d7719 100644
--- a/src/EventSubscriber/CspSubscriber.php
+++ b/src/EventSubscriber/CspSubscriber.php
@@ -73,7 +73,7 @@ class CspSubscriber implements EventSubscriberInterface {
     if (!$this->nonce) {
       // Nonce should be at least 128 bits.
       // @see https://www.w3.org/TR/CSP/#security-nonces
-      $this->nonce = rtrim(base64_encode(Crypt::randomBytes(16)), '=');
+      $this->nonce = Crypt::randomBytesBase64(16);
     }
 
     return $this->nonce;