客户端库
官方客户端是 onetime-ruby,它支持 API v1 和 v2、所有区域域名以及自定义基础 URL。
本页中的其他所有库均由社区维护。其中大多数库早于 API v2 和区域域名出现,因此通常会对 onetimesecret.com 调用已弃用的 v1 端点。请查看每个条目的状态说明,并在依赖某个库之前,先确认它能在您的区域或自托管实例上正常工作。
| 语言 | 库 | 最近活动¹ | 区域 / 自定义域名 |
|---|---|---|---|
| Ruby | onetime-ruby(官方) | 2026-06 | ✅ 所有区域 + 自定义基础 URL |
| Go | go-onetimesecret | 2026-05 | 美国主机 |
| Python | onetimesecret-cli | 2024-11 | 美国 / 欧盟区域选项 |
| Go | otsgo | 2024-03 | 未说明 |
| PowerShell | OneTimeSecret | 2021-06 | 自定义基础 URL |
| Bash | onetimesecret-bash | 2020-05 | 自定义主机 |
| Python | py_onetimesecret | 2019-05 | ❌(Python 2 时代) |
| C# | OneTimeSharp | 2018-05 | ❌ |
| Java | onetime-java | 2014-06 | 仅支持自托管 URL |
| Perl | Net::OneTimeSecret | 2012-02 | ❌ |
¹ 最近一次审核(2026-07)时的最新提交或发布。
GitHub 页面 - onetime-ruby 作者:Delano — 官方客户端,持续维护中(最近提交 2026-06)。支持 API v1(已弃用)和 v2、区域域名以及自定义基础 URL。需要 Ruby 3.1 及以上版本,无运行时依赖。
require 'onetime/api'
api = Onetime::API.new('YOUR_EMAIL', 'YOUR_OTS_APIKEY')options = { secret: 'Jazz, jazz and more jazz.', recipient: 'example@onetimesecret.com', ttl: 7200}
ret = api.post('/share', options)puts ret['secret_key']Python
Section titled “Python”GitHub 页面 - onetimesecret-cli 作者:slashpass — 社区维护(最近提交 2024-11)。支持区域选项(us / eu)。
from onetimesecret import OneTimeSecretCli
cli = OneTimeSecretCli(ONETIMESECRET_USER, ONETIMESECRET_KEY)cli.create_link("secret") # return a link like https://onetimesecret.com/secret/xxxxxxxxxxxGitHub 页面 - py_onetimesecret 作者:Vladislav Stepanov — 已停止维护(最近提交于 2019 年,下方示例为 Python 2)。仅对 onetimesecret.com 使用已弃用的 v1 API。
from onetimesecret import OneTimeSecret
o = OneTimeSecret("YOUR_EMAIL", "YOUR_OTS_APIKEY")secret = o.share(u"test")
print o.retrieve_secret(secret["secret_key"])# {u'secret_key': u'dtr7ixukiolpx1i4i87kahmhyoy2q65',# u'value': u'test'}CPAN 上的 Net::OneTimeSecret 作者:Kyle Dawkins — 已停止维护(最近发布 0.04 版,2012-02)。早于 API v2 和区域域名。
#!/usr/bin/env perl
use Net::OneTimeSecret;
# Note: replace these with yours in order for this to work!my $customerId = 'YOUR_EMAIL';my $testApiKey = 'YOUR_OTS_APIKEY';
my $api = Net::OneTimeSecret->new( $customerId, $testApiKey );my $result = $api->shareSecret( 'Jazz, jazz and more jazz.', passphrase => 'thepassword', recipient => 'kyle@shoffle.com', ttl => 7200, );printf( "%s\n", $result->{secret_key} );
my $secret = $api->retrieveSecret( $result->{secret_key}, passphrase => "thepassword" );printf( "%s\n", $secret->{value} );GitHub 页面 - onetime-java 作者:Marcin Pawlowski — 已停止维护(最近提交 2014-06)。接受实例 URL,因此可能适用于自托管部署,但早于 API v2。
OneTimeSecret ots = new OneTimeSecretRestImpl( "https://path/to/ots/instance", "ots-username", "ots-apikey");
GenerateResponse generateResponse = ots.generate( new GenerateRequest.Builder() .withPassphrase("supersecret") .build());
RetrieveResponse retrieveResponse = ots.retrieve( new RetrieveRequest.Builder() .withSecretKey(generateResponse.getSecretKey()) .withPassphrase("supersecret") .build());
assertEquals(generateResponse.getValue(), retrieveResponse.getValue());GitHub 页面 - OneTimeSharp 作者:Vladislav Stepanov — 已停止维护(最近提交 2018-05)。仅对 onetimesecret.com 使用已弃用的 v1 API。
// You can use OneTimeSharp in any of your projects which are compatible with .NET (4.0+) or Mono (2.10.8+).using VStepanov.OneTimeSharp;
class Test{ static void Main(string[] args) { var ots = new OneTimeSecret("YOUR_EMAIL", "YOUR_OTS_APIKEY");
var generated = ots.GenerateSecret();
Console.WriteLine(generated.Value); // LR*?us*A(UT*
Console.WriteLine(generated.SecretKey); // ikzx3m77j5by8411cg5lk5fvfylvl0i Console.WriteLine(ots.GetSecretLink(generated)); // https://onetimesecret.com/secret/ikzx3m77j5by8411cg5lk5fvfylvl0i
var shared = ots.ShareSecret("Hello, OTS!");
Console.WriteLine(shared.MetadataKey); // kd6rgsucl98qbgu9eavjq4k5sdxsom0 Console.WriteLine(ots.GetMetadataLink(shared)); // https://onetimesecret.com/private/kd6rgsucl98qbgu9eavjq4k5sdxsom0 }}GitHub 页面 - go-onetimesecret 作者:Corbalt — 社区维护(最近提交 2026-05,已更新为使用 us.onetimesecret.com 主机)。包含一个 CLI。
import ots "github.com/corbaltcode/go-onetimesecret"
client := ots.Client{ Username: "user@example.com", Key: "my api key",}
metadata, err := client.Put("the launch codes", "passphrase", 0, "")if err != nil { // handle error}
secret, err := client.Get(metadata.SecretKey, "passphrase")if err != nil { // handle error}
// prints "the launch codes"print(secret)CLI 使用示例
Section titled “CLI 使用示例”$ go install github.com/corbaltcode/go-onetimesecret/cmd/ots@latest
$ ots put 'what is essential is invisible to the eye'hdjk6p0ozf61o7n6pbaxy4in8zuq7sm ifipvdpeo8oy6r8ryjbu8y7rhm9kty9
$ ots get hdjk6p0ozf61o7n6pbaxy4in8zuq7smwhat is essential is invisible to the eye
$ ots genrVjbS$twCJkS 4nwhy7v4fnabayqc5auv4ogh0nfr20 flsdlaun6hwczqu9utmc0vts5xj9xu1
$ ots burn flsdlaun6hwczqu9utmc0vts5xj9xu1flsdlaun6hwczqu9utmc0vts5xj9xu1GitHub 页面 - otsgo 作者:Emídio Neto — 社区维护(最近发布 v1.1.0,2024-03)。未提供区域域名支持的相关文档。
// Build a new clientclient := ots.NewClient( WithUsername("otsuser@domain.com"), WithApiKey("xxxxxxxx"),)
// Send a request with contextctx := context.Background()response, err := client.GetStatus(ctx)if err != nil { panic(err)}
fmt.Println(response.Status)PowerShell
Section titled “PowerShell”GitHub 页面 - OneTimeSecret 作者:Craig Gumbley — 已停止维护(最近发布 2021-06)。支持自定义 -BaseUrl,因此可以指向某个区域或自托管实例,但早于 API v2。
# Install from the PowerShell galleryInstall-Module -Name OneTimeSecret -Scope CurrentUser
# Set connection informationSet-OTSAuthorizationToken -Username user@mail.com -APIKey xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
# Generate a new shared secretNew-OTSSharedSecret -Secret "Very Secret" -Passphrase 1234 -Recipient user@mail.com
# Retrieve a secretGet-OTSSecret -SecretKey qqevnp70b4uoiax4knzhwlhros6ne7x -Passphrase 1234
# View all functions that are availableGet-Command -Module OneTimeSecret | Select NameGitHub 页面 - onetimesecret-bash 作者:Eric Engstrom — 已停止维护(最近提交 2020-05)。支持通过 ots_set_host 设置自定义主机,但早于 API v2 和区域域名。
作为脚本 API 的使用示例
Section titled “作为脚本 API 的使用示例”# source for use anonymously (secrets created anonymously)source ots.bash
# or, source with specific auth credentialsAPIUSER="USERNAME"APIKEY="APIKEY"source ots.bash -u $APIUSER -k $APIKEY
# check status of serverots_status
# create a secret and get back the URLURL=$(echo "secret" | ots_share)
# share a multi line secret via HEREDOC.URL=$(ots_share <<-EOF This is a Secret ... on multiple linesEOF)
# pass options to share or generate.URL=$(ots_share ttl=600 \ passphrase="shared-secret" \ recipient="someone@somewhere.com" <<< "SECRET")
# fetch the secret datalocal DATA="$(ots_retrieve "$URL")"
# share/generate a new secret, and get back the private metadata keylocal KEY=$(ots_metashare <<< "SECRET")local KEY=$(ots_metagenerate)
# get a list of private metadata keys recently created.# note that this requires valid authentication credentialslocal -a RECENT=( $(ots_recent) )
# check on the current state of a secret, given the private keyots_state $KEY
# burn a secret, given the private keyots_burn $KEYCLI 使用示例
Section titled “CLI 使用示例”# Share a secret (from stdin)./ots shareSECRET^D
# Share a secret (via HEREDOC)./ots share <<-EOF This is a multi-line secret via HEREDOC. Something else goes here.EOF
# Get/Retrieve a secret:./ots get <key|url>./ots retrieve <key|url>
# Burn a secret, given its private metadata key:./ots burn <key>