Make encrypt_secret.py work with OpenSSL 0.x

The format was changed in 1.0. This enables Mac OS's default openssl CLI
tool to work with encrypt_secret.py

Change-Id: Ib5d7a0c5cc6a729bed6fa4a64193444bb48022fb
diff --git a/tools/encrypt_secret.py b/tools/encrypt_secret.py
index df4f449..9b52846 100755
--- a/tools/encrypt_secret.py
+++ b/tools/encrypt_secret.py
@@ -86,7 +86,12 @@
         if p.returncode != 0:
             raise Exception("Return code %s from openssl" % p.returncode)
         output = stdout.decode('utf-8')
-        m = re.match(r'^Public-Key: \((\d+) bit\)$', output, re.MULTILINE)
+        openssl_version = subprocess.check_output(
+            ['openssl', 'version']).split()[1]
+        if openssl_version.startswith(b'0.'):
+            m = re.match(r'^Modulus \((\d+) bit\):$', output, re.MULTILINE)
+        else:
+            m = re.match(r'^Public-Key: \((\d+) bit\)$', output, re.MULTILINE)
         nbits = int(m.group(1))
         nbytes = int(nbits / 8)
         max_bytes = nbytes - 42  # PKCS1-OAEP overhead