+ process = subprocess.run(
+ ['ssh-keygen', '-lEmd5', '-f-'],
+ input=key.encode('utf-8'),
+ stdout=subprocess.PIPE,
+ stderr=subprocess.PIPE)
+ if process.returncode != 0:
+ raise ValueError(process.stderr.decode('utf-8'))
+
+ output = process.stdout.decode('utf-8').rstrip()
+ m = re.match(
+ r'^(?P<bits>\d+) MD5:(?P<md5>[a-f0-9:]+) (?P<comment>.*) \((?P<algo>.*)\)$',
+ output
+ )
+ data['md5'] = m.group('md5')
+
+ return data
+