Skip to content

Instantly share code, notes, and snippets.

@jsorrell
Last active February 16, 2023 22:22
Show Gist options
  • Save jsorrell/7433e1e0a052b2160a8d5beaeafc52eb to your computer and use it in GitHub Desktop.
Save jsorrell/7433e1e0a052b2160a8d5beaeafc52eb to your computer and use it in GitHub Desktop.
Export TOTP secrets from Authy to use in another authenticator

Migrating from Authy to another authenticator

Last tested on Authy 2.5.0
Thanks to Guillaume's Gist and @puddly's comment

To use Authy's special 7 Digit TOTP's, ensure that they are supported by your authenticator

Instructions

  1. Ensure Google Chrome or Chromium is installed.
  2. Install Authy desktop app from the Chrome web store.
  3. Open Authy desktop app enter backup password to ensure all account TOTP's are visible.
  4. Go to Chrome's extensions page (chrome://extensions/?id=gaedmjdfmmahhbjefcbgaolhhanlaolb) and turn on developer mode (checkbox at top).
  5. Click on main.html under the Authy app in the chrome extensions page.
  6. A window should open with Chrome dev tools. Switch to the console tab.
  7. Check the link in the next step to Neocotic's QRious and ensure it is reputable.
  8. If so, copy everything from https://raw.githubusercontent.com/neocotic/qrious/master/dist/qrious.min.js and paste into the console.
  9. Audit the below code (make sure I'm not stealing your info) and paste into the console when satisfied. All account secrets shoud appear in the console.
/*
Copyright 2018 Jack Sorrell

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/

// From comment on https://gist.github.com/gboudreau/94bb0c11a6209c82418d01a59d958c93
function hexToB32(hex) {
	let alphabet = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ234567';
	let bytes = [];

	for (let i = 0; i < hex.length; i += 2) {
		bytes.push(parseInt(hex.substr(i, 2), 16));
	}

	let bits = 0;
	let value = 0;
	let output = '';

	for (let i = 0; i < bytes.length; i++) {
		value = (value << 8) | bytes[i];
		bits += 8;

		while (bits >= 5) {
			output += alphabet[(value >>> (bits - 5)) & 31];
			bits -= 5;
		}
	}

	if (bits > 0) {
		output += alphabet[(value << (5 - bits)) & 31];
	}

	return output;
}

// From comment on https://gist.github.com/gboudreau/94bb0c11a6209c82418d01a59d958c93
(function(console) {
	console.image = function(url, size) {
		console.log('%c+', `
			font-size: 1px;
			padding: ${Math.floor(size/2)}px;
			line-height: ${size}px;
			background: url(${url});
			color: transparent;
		`);
	}
})(console);

console.clear();
console.info('Below are your Authy TOTP secrets');
var accounts = appManager.getModel();
accounts.forEach(function(i) {
	var secret = (i.markedForDeletion === false ? i.decryptedSeed : hexToB32(i.secretSeed));
	var period = (i.digits === 7 ? '10' : '30');
	if (i.accountType.slice(0, 13) === 'authenticator') {
		console.groupCollapsed(i.name);
	} else {
		console.groupCollapsed(i.accountType.charAt(0).toUpperCase() + i.accountType.slice(1) + ': ' + i.name);
	}
	if (typeof secret === 'undefined') {
		console.warn('This account is encrypted. Make sure it is unlocked and avalable in the Authy app.')
		console.groupEnd();
		return;
	}
	console.log('TOTP Secret:', secret);
	var totpUri = 'otpauth://totp/' + encodeURIComponent(i.name) + '?secret=' + secret + '&issuer=' + i.accountType + '&digits=' + i.digits + '&period=' + period;
	console.log('TOTP URI:', totpUri);
	console.log('QR Code (Google Chart API):', 'https://www.google.com/chart?chs=200x200&chld=M|0&cht=qr&chl=' + encodeURIComponent(totpUri));
	const qrSize = 300;
	var qrUrl = (new QRious({
		value: totpUri,
		size: qrSize
	})).toDataURL();
	console.image(qrUrl, qrSize);
	console.groupEnd();
});
if (typeof accounts === 'undefined' || accounts.length === 0) {
	console.warn('Nothing found. Make sure to log in to Authy and have the Authy window open.');
	'0 found'; //give console a result
} else {
	accounts.length + ' found'; //give console a result
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment